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.
65 Replies
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');
Hi Nicola,
Give this a try instead:
Note, I haven't tested this, but hopefully it'll do the trick.
Unfortunately it won't launch an email at all now. I've been puzzling over this for the past week. Thank you for trying though - I appreciate you responding so quickly :-)
That's odd, I must have done something silly when editing your code.
Try this instead:
Perfect! Thanks so much Matthew, it's working now. You've saved me another day of headaches! Have a great day :-)
Wonderful! That's what I like to hear. All the best Nicola.
Matt, I haven't tried out your example yet but was wondering if it works with web-based email accounts such as gmail. Most of the solutions I have come across don't work with web mail.
Hey Nancy,
It depends on how the user has configured things. I'm a Gmail user and it works perfectly for me, but I've also gone through the steps to set Gmail as my default email client, which is something that not everyone does.
Hi Matthew - are you talking about the Browser settings in Chrome? I have set Gmail as my default email client in Chrome, but was wondering if there is another way to do this so that I can use any browser and it works?
Hey Nancy,
It needs to be set up on a per browser basis. This article (while a couple of years old) shows how to set Gmail as the default email in each of the major browsers.
Thanks for this Matthew.
No problem Nancy.
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
Hi again!
I may have just found it. I managed to forget to declare some of the variables from SL into JS - doh! (Too much text!) I will fix and come back and update my post accordingly.
Thanks for your patience!
Caryn
Nope - that didn't fix it. But here is an updated version of the script.
Best,
Caryn
What happens if you delete this line?
emailBody = encodeURIComponent(emailBody);
Thanks for the suggestion, Owen! Alas, no difference.
Hey Caryn,
Your code references variables that don't exist.
For example,
ImpactNotes
,ImpactNotes1
,ImpactNotes2
,BuildNotes
,BuildNotes2
, and there are plenty more.Hey Matthew,
Thanks for all the help - you are a HERO!
-Caryn
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.
Yes, that is possible Brian.
What are the variables you are using in your course? Happy to help get your JS ready...
Hi Matthew. My variables are Q1 through Q15.
Thank you so much for your help!
Try this:
I haven't tested this, so not 100% sure it works...
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?
Possibly. Can you share your code here Brian?