Pulling text entries from SL360 and sending via email - Javascript

Sep 24, 2020

Hi All,

I've seen some posts on this topic but none have helped me, so I apologize if I've missed it...

I've got a course with four scenarios and accompanying freeform text entry boxes for each. I want the learner to click an email button at the end of the course and send the scenarios, their accompanying questions, and the learner's text from the freeform boxes in an email. 

I can get the first scenario to launch in email (with the scenario, Q's 1, 2, and 3, and the learner's answers. Or I can get the second scenario to launch in email. But not both together. Here's the js code I've used:

var player = GetPlayer();
var email = '';
var ans1 = player.GetVar('scenario1Q1');
var ans2 = player.GetVar('scenario1Q2');
var ans3 = player.GetVar('scenario1Q3');
var ans4 = player.GetVar('scenario2Q1');
var ans5 = player.GetVar('scenario2Q2');
var ans6 = player.GetVar('scenario2Q3');
var subject = 'Course Name';
var emailBody = 'SCENARIO 1: This is a description of the first scenario. ' + '\n' + 'Q1: This is the first question? ' + '\n'
+ 'My answer: ' + ans1 + '\n\n'
+ 'Q2: This is the second question? ' + '\n'
+ 'My answer: ' + ans2 + '\n\n'
+ 'Q3: This is the third question?' + '\n' + 'My answer: ' + ans3 + '\n\n'
+ 'SCENARIO 2: This is a description of the second scenario.' + '\n' + 'Q1: This is the first question? ' + '\n'
+ 'My answer: ' + ans4 + '\n\n'
+ 'Q2: This is the second question? ' + '\n'
+ 'My answer: ' + ans5 + '\n\n'
+ 'Q3: This is the third question?' + '\n' + 'My answer: ' + ans6;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');
//window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);

 

I'm a js novice so any suggestions are welcome! Thanks so much!

 

  

10 Replies
Shonna Falco

Ah thank you for that! So, here's my next curiousity...when I used your code I did get the email window to launch and the text was formatted correctly. However, when I use my actual text it's not working again. Here is my code with the actual text (not placeholder):

var player = GetPlayer();
var email = '';
var ans1 = player.GetVar('scenario1Q1');
var ans2 = player.GetVar('scenario1Q2');
var ans3 = player.GetVar('scenario1Q3');
var ans4 = player.GetVar('scenario2Q1');
var ans5 = player.GetVar('scenario2Q2');
var ans6 = player.GetVar('scenario2Q3');
var subject = 'Epic Service Returner - Module 4 Inputs';
var emailBody = 'SCENARIO 1: A family is looking for some things for the kids to do on their winter vacation. The mother is tired and a bit frazzled, and one of her kids is having a meltdown. She has a three year old son and a seven year old daughter. ' + '\n' + 'Q1: How will you adapt your communication to connect with this family? What might the guests’ body language, tone, and spoken word tell you about how they are feeling? What will you do with your body language to help these guests feel happy, excited, relaxed, and safe? What will you say and what will your tone be? ' + '\n' + 'My answer: ' + ans1 + '\n\n' + 'Q2: What open-ended questions can you ask to engage with the guest and put the focus of the conversation on them? To make them feel supported and taken care of? ' + '\n' + 'My answer: ' + ans2 + '\n\n' + 'Q3: What sorts of things will you suggest to help this family feel happy, excited, relaxed, and safe while visiting your resort? To improve their situation and create memorable moments that will culminate in the experience of a lifetime?' + '\n' + 'My answer: ' + ans3 + '\n\n' + 'SCENARIO 2: A man is staying at your resort a couple of days after his work conference ended and wants some suggestions of what he can do. He’s reserved and wants to take advantage of some time alone.' + '\n' + 'Q1: How will you adapt your communication to connect with this family? What might the guests’ body language, tone, and spoken word tell you about how they are feeling? What will you do with your body language to help these guests feel happy, excited, relaxed, and safe? What will you say and what will your tone be? ' + '\n' + 'My answer: ' + ans4 + '\n\n' + 'Q2: What open-ended questions can you ask to engage with the guest and put the focus of the conversation on them? To make them feel supported and taken care of? ' + '\n' + 'My answer: ' + ans5 + '\n\n' + 'Q3: What sorts of things will you suggest to help this family feel happy, excited, relaxed, and safe while visiting your resort? To improve their situation and create memorable moments that will culminate in the experience of a lifetime?' + '\n' + 'My answer: ' + ans6;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');
//window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);

 

-------------------------

Is it too long by chance? Or other thoughts?

Shonna Falco

Oh that's interesting. I use MS Outlook and here's what my email looks like (attached). I only get the first Scenario and its questions/answers.

There are actually 4 scenarios and we ask the learner to answer 3 questions for each scenario. The questions are the same for each scenario but I worry that they are fairly long. The answers won't be that long (is my guess). 

I suppose I would likely need to at least reformat the js for the email output so I'm not repeating the 3 questions for every scenario; instead maybe showing them once. 

Anyway, other thoughts are appreciated if you have them!

Thanks again for helping out,

Shonna

 

 

 

 

Shonna Falco

HI Matthew, I'm attaching my .story file if you still have time to take a peek. If I can use the email output option, that's preferred. If it's not going to work I will try the PDF route.

My email link is on the last page (Module Conclusion). And, you'll see the four scenarios with their accompanying questions separated out by Scene.

Thanks again for helping. I really appreciate it!

 

Shae Zeitz

I've been trying to replicate this same experience (emailing variable content with executed java script) but I cannot get it to work. I get halfway there: I'm able to generate a new browser tab (via each of the below separate sets of java), but no Outlook email generates. Each of them, when tested separately, only opens a Chrome browser tab.

What am I doing wrong? I need it to generate an Outlook email.

var player = GetPlayer();
var email='';
var subject='Tracks Course Notes';
var feedback=player.GetVar('MyNotes');
var emailBody = +feedback
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);
win=window.open(mailto_link,'emailWin');

 

--------------------------

var player = GetPlayer();

var useremail=player.GetVar("Email");

var subject="Tracks Training Notes";

var notes1=player.GetVar("MyNotes");

var content="Tracks Training Notes%0d%0A%0d%0A";

content+=notes1;

var mailto_link='mailto:'+useremail+'?subject='+subject+'&body='+content;

win=window.open(mailto_link,'emailWin');

 

-------------------------------

var player = GetPlayer();
var email=player.GetVar("Email");
var subject="Tracks Training Feedback";
var body_start=player.GetVar("MyNotes");
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+escape(body_start);
emailwin=window.open(mailto_link,'emailWin');
emailwin=window.close();