Pulling text entries from SL360 and sending via email - Javascript

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!

 

  

13 Replies
Matthew Bibby

See if this is any better:

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');
Matthew Bibby

You had line breaks before many of the + symbols, which can be misinterpreted by the browser.

So your code looked like this (note how many of the + symbols are on the left):

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');

Whereas mine looked like this:

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');
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

 

 

 

 

Matthew Bibby

I'm not sure why you are seeing something different. If you want to send me your .story file, I'll take a look.

It might be confusing for learners if you remove the questions. 

Other options are:

  • Avoiding mailto: limitations by using a server to send the email. This is a bit complex to setup and may have ongoing costs if you're sending lots of emails.
  • Outputting this information to a PDF rather than email. Then the learner can email the PDF if they want. 
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!

 

Matthew Bibby

The email only included the first scenario as that's all it was told to do!

This is the code that was in your project:

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;
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);

As you can see above, only the first scenario was included. Whereas if you use this code:

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\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\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');

 It will include two scenarios.

Hope that helps.