Tutorial: Populating an Email with Content from Storyline

Have you ever needed to email some information out of Storyline, but didn't know how to set it up?

In this tutorial we will write some JavaScript that will grab variables from within Storyline and pop them in an email ready for the learner to send.

Click here to see the demo and here to download the source file.

If you'd like to take this concept further, you can also do things like grab the users name from the LMS to use it these emails, note system info which may help during QA/testing and create custom reports based on the learner's performance.

Let me know if you have any questions.

36 Replies
Nicola Thomas

Thanks for this Matthew. I've tried it and it's not pulling the variable through. Can you see where I've gone wrong?

 

var player = "GetPlayer()";
var email = "nicolathomas@reedmac.co.uk";
var fbk = "player.GetVar('TotalScore')";
var subject = "Enter me in the competition";
var emailBody = 'My total score is:' + fbk;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');

Matthew Bibby

That's odd, I must have done something silly when editing your code.

Try this instead: 

var player = GetPlayer(); 
var email = 'nicolathomas@reedmac.co.uk'
var score = player.GetVar('TotalScore');
var subject = 'Enter me in the competition';
var emailBody = 'My total score is: ' + score;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');
Caryn Carman

Hi Matthew!

I've been referencing your post here as well as the tutorial on your blog and both have been tremendously helpful - thank you!

I had a quick question. Is there any limit to the number of email generating scripts one can use within a story? 

I have one in place that's working fine but when I add another script from a different slide and different trigger (using the same code with some additional body text), the email window doesn't pop up. I've checked quotes, syntax, variable names, etc and tried throwing it into Sublime, but haven't been able to find the bug.

I've attached a text file here in case you have a moment to glance at it or have any other suggestions.

Many thanks!
Caryn

Brian McCann

Hi Matthew,

Can this be used to draw multiple variables from a course and plugged into the email? What would the Javascript look like if the body of the email was to appear like:

Question

*variable pulled answer*

Question

*variable pulled answer*

I tried changing your code to make that work, but it only populated the email body with the last variable, rather than all of them. My javascript knowledge is nearly nonexistence.

Thank you much.

Matthew Bibby

Try this:

var player = GetPlayer();
var email = 'your_email@address.com';
var q1 = player.GetVar('Q1');
var q2 = player.GetVar('Q2');
var q3 = player.GetVar('Q3');
var q4 = player.GetVar('Q4');
var q5 = player.GetVar('Q5');
var q6 = player.GetVar('Q6');
var q7 = player.GetVar('Q7');
var q8 = player.GetVar('Q8');
var q9 = player.GetVar('Q9');
var q10 = player.GetVar('Q10');
var q11 = player.GetVar('Q11');
var q12 = player.GetVar('Q12');
var q13 = player.GetVar('Q13');
var q14 = player.GetVar('Q14');
var q15 = player.GetVar('Q15');
var subject = 'Your Subject Goes Here';
var emailBody = 'Question 1:' + '\n' + q1 + '\n' + 'Question 2:' + '\n' + q2 + '\n' + 'Question 3:' + '\n' + q3 + '\n' + 'Question 4:' + '\n' + q4 + '\n' + 'Question 5:' + '\n' + q5 + '\n' + 'Question 6:' + '\n' + q6 + '\n' + 'Question 7:' + '\n' + q7 + '\n' + 'Question 8:' + '\n' + q8 + '\n' + 'Question 9:' + '\n' + q9 + '\n' + 'Question 10:' + '\n' + q10 + '\n' + 'Question 11:' + '\n' + q11 + '\n' + 'Question 12:' + '\n' + q12 + '\n' + 'Question 13:' + '\n' + q13 + '\n' + 'Question 14:' + '\n' + q14 + '\n' + 'Question 15:' + '\n' + q15;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');

I haven't tested this, so not 100% sure it works...

Brian McCann

Thanks, Matthew!

It works when I put your code into my project, but when I try changing Question 1 to show the actual question, nothing happens when I execute the Javascript in the project.  Would including question marks in my questions (ex: Replacing 'Question 1:' with 'What did Bill do wrong?') break the Javascript?