Export Variable Values via Email Message using JavaScript

Ever wish you had visibility into how users are interacting with the courses you create, such as which slides they’re viewing, what answer they selected in each question of a quiz? Well, you can have visibility into this using Storyline Variables and JavaScript! 

This article explains how to export variable values from a Storyline file into the body of an email message using JavaScript. This can be done either by using pre-defined “To” and “Subject” fields or by using JavaScript to populate the “To” and “Subject” fields with user-specified variable values.

This functionality has many benefits. It provides as much visibility into how the user is interacting with the course as you desire, depending on how much variable programming you build into your course. If you want to just receive an email when a user completes a course, you can use this programming for something that simple. Or, if you’re like me and want a lot more visibility into the inner workings of how a user is interacting with the course, you can program it so that the email message contains information on which slides the user viewed, what answer they selected for each quiz question, their overall quiz score, the values of any entry fields they typed text/numbers into within the course, and much more. Anything with a Storyline variable value associated with it can be exported via email.

 

Instructions:

1.      Build your course, including all variables and triggers to adjust the variables as needed throughout the course. If desired, add a text entry field somewhere in the course where the user can specify the email address where these variable values should be sent. You can do the same thing if you would like the user to specify the subject of the email message via text entry field. If you are using this method, ensure you require the user to populate these fields (prevent them from leaving these fields blank).

2.      On the last slide of the course, or whichever slide you would like this email sent from, add the trigger with the JavaScript code listed below.

Note: This can be placed on whatever object is applicable to your course, such as a submit button, upon timeline start of the slide, etc.

 

Within the body_start section, you can add as many of the player.GetVar(“VariableName”) actions as you need to pull in as many variable values as desired. In addition, you can insert any plain text in quotation marks “ “. Just be sure to add a plus sign (+) between each aspect of this function to ensure it is all added as a text string.

 

Populate Email Message with Pre-Defined Email Address and Subject:

Action: Execute JavaScript

Script:

var email="YourEmailAddress@email.com";

var subject="Subject Goes Here";

var player = GetPlayer();

var body_start= “Any basic text you want to include, just place it in quotation marks " + player.GetVar("YourVariable1Name") + “Any other basic text you want to include " + player.GetVar("YourVariable2Name");

var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start;

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

When: (Desired Action)

Object: (Desired Object)

 

Populate Email Message with User-Defined Email Address and Subject:

Action: Execute JavaScript

Script:

var player = GetPlayer();

var email= player.GetVar(“UserDefinedEmailVariableName”);

var subject= player.GetVar(“UserDefinedSubjectVariableName”);

var body_start= “Any basic text you want to include, just place it in quotation marks " + player.GetVar("YourVariable1Name") + “Any other basic text you want to include " + player.GetVar("YourVariable2Name");

var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start;

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

When: (Desired Action)

Object: (Desired Object)

  

3.      Publish the course to HTML to test. Note: You cannot test JavaScript using Preview mode.

 

4.      Test the trigger (click the button, view the slide, etc.) which activates the JavaScript programming within your course.

 

5.      An Email Message opens with the contents of the Variable values and plain text displayed.

 

6.      Click Send to send the Variable values and plain text to the designated user(s).

 

For additional information regarding JavaScript & Storyline 2, see the article:

https://articulate.com/support/article/javascript-best-practices-and-examples-sl2

 

Happy Programming!

7 Replies
Bridget O'Dell

Hi John,

Unfortunately I don't think this is possible (at least not per my knowledge and testing).

The email message that is sent has a very basic formatting (only contains any plain text that was a part of the JavaScript and any variable values that are configured to be a part of it) and pre-configured email templates cannot be used. In addition, to my knowledge there is no way to send an email without the learner clicking "send" within the email message that appears. 

If you're looking for sending results to something without the learner's knowledge you may need to use an LCS and xAPI or API or look into exporting data to a spreadsheet like Google Spreadsheets - I know there are several articles on how to do this on this site.

Hope that helps!

John Fritts

Hi Starla and All, I have learned enough about JavaScript on my own and through the help of others that I have arrived at an acceptable solution. The goal was create quizzes where the results are sent to a mgmt. reviewer for analysis without the quiz taker seeing the results. I have used an Execute JS Trigger, extracted SL variable values and encrypt the quiz results with each answer in the email. If answered wrong, the text is Qn = Monday, if answer correct, Qn = Any day of the week but Monday.  My sample quiz and results email are attached.