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.

58 Replies
Matt Smith

Hi Matthew

I'm having an issue - i can't get the cc or the subject line to populate:

https://mattsmeeth1.s3.eu-west-2.amazonaws.com/story.html 

Here's the code, can you help spot what's wrong? I'm new to Javascript! 

var player = GetPlayer();
var A = player.GetVar('A');
var B = player.GetVar('B');
var C = player.GetVar('C');
var email1 = player.GetVar('Email1');
var email2 = player.GetVar('Email2');
var ImprovementAreas = player.GetVar('ImprovementAreas');
var MidwifeReviewed = player.GetVar('MidwifeReviewed');
var ReviewDate = player.GetVar('ReviewDate');
var ReviewingMidwife = player.GetVar('ReviewingMidwife');
var subject = 'Scoring Tool for Documentation Audit: Midwifery out-patient ante natal care';
var emailBody = 'Midwife Reviewed: ' + MidwifeReviewed + '\n' + '\n' + 'Reviewing Midwife: ' + ReviewingMidwife + '\n' + '\n' + 'Review Date: '+ ReviewDate + '\n' + '\n' + 'Audit Result:' + '\n' + '\n' + 'Answer A: ' + A + '\n' + 'Answer B: ' + B + '\n' + 'Answer C: ' + C + '\n' + '\n' + 'Areas for Reflection:' + '\n' + ImprovementAreas + '\n' + '\n' + 'Descriptor reminder:' + '\n' + '\n' + 'Mostly Answer A:' + '\n' + 'Very Well done' + '\n' + 'Keep up the good work' + '\n' + '\n' + 'Mostly Answer B:' + '\n' + 'Satisfactory' + '\n' + 'Some areas for improvement required to your documentation' + '\n' + '\n' + 'Any Answer C given:' + '\n' + 'Unsatisfactory' + '\n' + 'Some major areas of concern' + '\n' + 'Action plan to be made with manager including regular repeat documentation audit';
var mailto_link = 'mailto:' + email1 + '?cc' + email2 + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');
setTimeout(function() { win.close() }, 100);

Joel Andrews

Hello Matt & Staff & Others, 

I appreciate & value the examples, comments, and assistance given. I am in need of some help right now. I am trying to implement some javascript into a project - to allow users to email themselves 'notes' taken throughout the course. Definitely a rookie at using code; here's what it looks like: (attachments) 

In file - on slide 20  

Thank you all! 

Sherri Sagers

I have found that I have to be very conservative about the number of characters that get passed into the email. Things start getting cut off at a certain point and it seems like it might be different depending on the default email client (Outlook/Gmail/WebOutlook, etc.). I try to keep it under 1,000 characters.

Matthew Bibby

Yes, that's correct Sherri. This is due to the mailto: spec, which unfortunately doesn't specify a max-length. You can find out more about that here.

I don't use the mailto: approach very often for this reason. If I need to capture lots of info from SL variables, I'd normally output to PDF and then use an external server to send that via email if needed.