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.

47 Replies
Brian McCann

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 = 'Corporate Work Environment Situational Awareness Training Results';

var emailBody = 'For the scenario involving a rude manager during a meeting, what was your first response? Would you still choose this style?' + '\n' + q1 + '\n' + 'What is your confidence in doing this intervention choice in your workplace?' + '\n' + q2 + '\n' + 'Given your intervention approach, how likely do you think the rude manager’s behavior will remain an issue?' + '\n' + q3 + '\n' + 'For the scenario involving arguing coworkers, what was your first choice? Would you still choose this style?' + '\n' + q4 + '\n' + 'What is your comfort level in doing this intervention choice in your workplace?' + '\n' + q5 + '\n' + 'Given your intervention approach, is it likely that the coworkers will continue to argue?' + '\n' + q6 + '\n' + 'For the scenario involving the irritable coworker snapping at her colleagues, which choice did you make first? Would you still choose this intervention style?' + '\n' + q7 + '\n' + 'What is your comfort level in doing this intervention choice in your workplace?' + '\n' + q8 + '\n' + 'Given your intervention approach, how successfully do you think this will improve the workplace?' + '\n' + q9 + '\n' + 'For the scenario involving the recognition of a colleague’s hard work, what was your first choice? Would you still choose this intervention style?' + '\n' + q10 + '\n' + 'What is your comfort level in doing this intervention choice in your workplace?' + '\n' + q11 + '\n' + 'Given this discussion, how will you recognize peer contributions moving forward?' + '\n' + q12 + '\n' + 'For the scenario involving the manager taking credit for others’ work, what was your first choice? Would you still choose this intervention style?' + '\n' + q13 + '\n' + 'What is your comfort level in doing this intervention choice in your workplace?' + '\n' + q14 + '\n' + 'Given your intervention approach, how likely is it employees will remain working for this boss?' + '\n' + q15;

var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);

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

Matthew Bibby

I just had a quick look and couldn't see anything obviously wrong with your code.

How are you testing this?

Keep in mind that JavaScript won't work when viewing your course locally (unless you are only viewing the HTML5 output). So if you haven't already I'd try uploading your course to its intended environment and see if that helps.

If it doesn't, let me know, and I'll help you get to the bottom of it.

Caryn Carman

Hey Matthew!

I see this thread is as popular and timely as ever! The script you helped me with has been working like a charm. But this week, two individuals had the same issue which I've not seen before and was just able to replicate. Wondering if you've ever come across it.

Basically, the learner goes through the course and enters data setting the variables. The variables are being correctly stored. But when they click the button to run the script to collect the variables and dump them into a draft email, they get the (expected) blank browser tab with what looks like all the script data dumped into the browser address bar AND no actual draft email. 

The strangest thing is that for one of these learners, I was able to login as them, go into the course, and trigger all the emails as designed. BUT for the other, 3 of the 4 scripts / emails worked but one didn't.

Any ideas, no matter how wild?

Devoted fan,


Matthew Bibby

Thanks for your kind words Caryn.

As far as wild ideas... you'd be amazed how nice Kale tastes if you massage some olive oil into the leaves, cover with parmesan and pop in the oven for a few minutes.

My guess is that those users don't have an email client setup or configured on their computer. That would explain most of the behaviour you are seeing. 

What's confusing is that for some users some emails are working some of the time. Maybe there is an issue with the length of the responses they are entering? Try just entering one word in each field to see if it makes a difference.

Let me know...

Caryn Carman

Yes, I'd also assumed it must be that the default email client wasn't set up, but alas, why would it be so simple? I don't recall her answers being longer than anyone else's but will absolutely go back in and look. 

Sorry - love all manner of veg (esp with cheese), but alas, still not sold on the kale.  ;)

Brian McCann

Thanks for the response. I've tried uploading it to the intended environment and that hasn't helped.

Comparing my code to your original code, I think there was an extra semi-colon at the end of the second line, but I tried removing that and it still doesn't work.

I saw a post somewhere else on the forum that said there's a limit to the number of characters that the Execute JavaScript trigger can handle. Might that be the problem?

Brian Corner


I have taken your script example and modified it with the two variables I'm using. When testing after publishing the course, it will not open an email window. It's an internal corporate course where everyone is using Outlook. I've tried in both IE and Chrome with no success.  I have used a simple "send email to" trigger that works fine, but I want to be able to pass along the variables. Any suggestions?  Thank you.

var player = GetPlayer();
var email = 'myemail@domain.com'
var found = player.GetVar('MROFound');
var match = player.GetVar('MatchCorrect');
var subject = 'Results';
var emailBody = 'MRO Found is: ' + found + 'Items matched is:' + match;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');

Estelle Drysdale

Thanks for a very insightful thread :-) I learned a lot.

I am trying to both email and print. My challenge is that the user can answer 6 questions and based on their answer they will get feedback. But what happens is that if an option is not applicable it creates an empty line. Is there a way that like in your above example where you concatenated the answers to these questions, one can add a condition to that?

I tried using for each element a condition and adding to the results variable based on whether that option was selected yes or not, but I still end up with the spaces. (Refer to slide 2 on the build variables layer)

Attached an extract from my project.

Any help would be appreciated. Thanks.

Mark Dowman

Love this solution, but it has one drawback for us. An extra blank tab is opened in the browser, when the email is brought up. Is there a way to automatically close that tab, so the student is returned to the lesson?

I assume it is from the last line in the script.

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

Any ideas on a solution?

Mary Hillis


Thank you for all of this great information in sharing variable content via email! This is my first storyline 2 project as I am new to instructional design, but hoping for some guidance.

I have text responses (variables) I am hoping will populate in an email users can send themselves.

The var are attached via screenshot.

The code I have is as follows:

var player = GetPlayer();

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

var subject = "How Education Changed My Life";

var emailBody= 'Great job creating your story:' + '\n' + 'Onceupon'+'/n'+'Everyday'+'/n'+'Untiloneday'+'/n'+'Becauseofthat'+'/n'+'Because2'+'/n'+'Untilfinally'

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


Any insight into what I am missing?

Russell Killips

Hi Mary,

The emailBody line should use '\n' instead of '/n'. That line of code also needs a ; at the end.

You are also missing a line of code just before the last line of code.

var mailto_link = 'mailto:' + useremail + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);

Mark Dowman

I found a piece of code that closes the spawned tab. It works pretty fast.

var player = GetPlayer();
var email = 'person@website.com'
var notes = player.GetVar('TextEntry');
var subject = 'Lesson Feedback – Scenario 4';
var emailBody = 'Scenario 4' + '\n' + '\n' + notes;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');
setTimeout(function() { win.close() }, 100);

This last line closes the blank tab in 1/10 (ish) of a second.

Sebastin Francis

Hi Matthew,
Excellent tutorial and all the codes and ideas you shared have been very helpful. I'm just popping in to share something that I hope will help others about that extra, blank tab opening. At the end of your tutorial, you provided the updated code with the caveat that if one has set up a default mail client (e.g., Gmail) on their browser(s), this might cause some minor annoyance. I found a minor change, tested in on my Chrome (I have gmail set up as default on my Chrome) and it works great (i.e., no extra/blank tabs, nor any issues). 

Here's that minor change:



window.location.href = mailto_link;

Hope this helps!