Question: How to email result slide

Hello all,

I am working on a project that allows people to complete a self-assessment and then email the results to their managers.  The result slide consists of a table and multiple check marks (images). 

I tried using the following JS from another discussion thread - but nothing gets attached. 

var player = GetPlayer();
var email = player.GetVar("ManagerEmail");
var name = player.GetVar("name");
var texto = player.GetVar("Commitment") + "\n";
var subject = "My Competency 180 Self-Assessment";
var body_start = "Dear Manager,\n" + name + " has sent you his/her Competency 180 Self-Assessment:\n";
var body_end = "Please discuss this self-assessment with " + name + "\n";
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(body_start + texto + body_end);
win = window.open(mailto_link, 'emailWin');

 

I assume I am missing something.  I am not very good with JS, so I am not too sure what the var texto is for.  I assume this is a key piece that I am missing.  This script is specific to the thread from which I took the JS, so I am not too sure how to edit for my project.

Any help would be greatly appreciated.

Thanks!

 

 

15 Replies
Matthew Bibby

Hi Sean,

I'll talk you through the code you've included:

var player = GetPlayer(); - This establishes communication with Storyline.

var email = player.GetVar("ManagerEmail") - Here we are getting the value of a Storyline variable called ManagerEmail and storing it in a JS variable called email

var name = player.GetVar("name"); - Getting the value of a Storyline variable called name and storing it in a JS variable called name.

var texto = player.GetVar("Commitment") + "\n"; - Getting the value of a Storyline variable called Commitment and storing it in a JS variable called texto. Then, adding a new line to the end of that text. 

var subject = "My Competency 180 Self-Assessment"; - Creating a JS variable called subject and setting it's value to My Competency 180 Self-Assessment

var body_start = "Dear Manager,\n" + name + " has sent you his/her Competency 180 Self-Assessment:\n"; - Creating a JS variable called body_start and giving it the following text: 

      Dear Manager,

      [name] has sent you his/her Competency 180 Self-Assessment:

(But of course the [name] part will be replaced with the users name, which was originally stored in a Storyline line variable called name.)

var body_end = "Please discuss this self-assessment with " + name + "\n"; -  Here we are creating a new JS variable called body_end and giving it the value of: Please discuss this self-assessment with [name] 

var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(body_start + texto + body_end);  - Here we are creating a JS variable called mailto_link that is combining all of the different parts into a format that can be used to create a new email.

Essentially this is saying 'Create a new email, fill the To: field with the ManagerEmail address from Storyline. Give the email the subject "My Competency 180 Self-Assessment", respect all special characters including new line breaks and in the body of the email, include the following:

      Dear Manager,

      [name] has sent you his/her Competency 180 Self-Assessment:

      [Whatever text is stored in the Commitment variable in Storyline will be included here]

      Please discuss this self-assessment with [name]

win = window.open(mailto_link, 'emailWin'); - This will then open a new window, which will execute the mailto_link which all going to plan, should result in a new email being opened in the users default email program containing the above info.

So for this code to work, you'll need the following text variables set up in Storyline:

  1. ManagerEmail
  2. Name
  3. Commitment

You will then need an Execute JavaScript trigger setup that includes your code. 

And when you test it, you'll either need to test the HTML5 version or upload the course to a server or LMS (e.g. Tempshare, SCORM Cloud, Amazon S3, Dropbox etc.)

Note that an attachment of the results slide will not be attached to the email. Any information you want sent will need to be added to the Commitment variable in Storyline or this code will need to be modified.

I hope this explanation is helpful. Let me know if you have any questions.  

Sean Ludlam

Hi Matthew,

I have attached an image of the slide.  Basically, the user goes through a series of 8 questions to self-assess where he/she is on a proficiency scale.  I have variables to track the responses.  The results slide then makes visible a check mark based on the variable triggered. 

As mentioned, I want the user to be able to email the slide to his/her manager. 

Thanks for any assistance you can provide!

Christie Pollick

Hi, Sean -- Thanks for reaching out and I see that Matthew is providing you with some great guidance here! I thought I might stop in to note in case you were unaware, JS coding is not something for which we are able to offer support, but I wanted to pass along this sheet with our JavaScript Best Practices and Examples

Matthew Bibby

Hi Sean,

Yeah, that's going to be tricky. I don't think that I can set it up so a copy of that slide is sent, however you could capture the same info in the email.

Would something like this suffice?

      Dear Manager,

      [name] has sent you his/her Competency 180 Self-Assessment:

      [name] is an expert at relationships.

      [name] is advanced at communication.

      etc.

      Please discuss this self-assessment with [name]

Sean Ludlam

Hi Matthew,

It seems that I was overconfident in my ability to edit the JS.  I tried and the email window didn't even launch.

I am trying to add to the body text of the email a list of the competency names & the self-assessment score that is being generated from variables within Storyline. 

I want the body to read something like this:

Competency 1= underskilled (which would is generated from the user with a text variable of C1)

Competency 2=(value of C2 text variable)

Competency 3=(value of C3 text variable)

So on for the 8 competencies. 

I would appreciate any direction you can provide.

Many thanks - Sean

Matthew Bibby

Hi Sean,

Give this a try:

var player = GetPlayer();
var email = player.GetVar("ManagerEmail");
var name = player.GetVar("name");
var c1 = player.GetVar("C1");
var c2 = player.GetVar("C2");
var c3 = player.GetVar("C3");
var c4 = player.GetVar("C4");
var c5 = player.GetVar("C5");
var c6 = player.GetVar("C6");
var c7 = player.GetVar("C7");
var c8 = player.GetVar("C8");
var subject = "My Competency 180 Self-Assessment";
var body_start = "Dear Manager,\n" + name + " has sent you his/her Competency 180 Self-Assessment:\n";
var body_middle = "Competency 1 = " + c1 + ".\n" + "Competency 2 = " + c2 + ".\n" + "Competency 3 = " + c3 + ".\n" + "Competency 4 = " + c4 + ".\n" + "Competency 5 = " + c5 + ".\n" + "Competency 6 = " + c6 + ".\n" + "Competency 7 = " + c7 + ".\n" + "Competency 8 = " + c8 + ".\n";
var body_end = "Please discuss this self-assessment with " + name + "\n";
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(body_start + body_middle + body_end);
win = window.open(mailto_link, 'emailWin');