Storyline2 Javascript for sending email issue

Aug 06, 2015

Hello all! I have created a javascript button trigger that writes variables to an email to send question results (I show the question then the answer) to a manager at a certain email address. It works well, but I have a total of 54 variables that are called through player.GetVar(); but the script stops working after the 46th variable is called. Is there a limitation on the number of variables that can be handled by a javascript trigger? The code has been validated and should work. Any thoughts? Is there another way around this? I need to get an answer quickly as I'm under a deadline! Thanks!

var email = "any.email@youremail.com";
var cc = "body_start[10]";
var subject = "Configuration Report";
var player = GetPlayer();
var body_start = new Array();
body_start[0] = player.GetVar("Name");
body_start[1] = player.GetVar("FullName1");
body_start[2] = player.GetVar("City");
body_start[3] = player.GetVar("CityName1");
body_start[4] = player.GetVar("Q1");
body_start[5] = player.GetVar("Q1Final");
body_start[6] = player.GetVar("Q2");
body_start[7] = player.GetVar("Q2Final");
body_start[8] = player.GetVar("Q3");
body_start[9] = player.GetVar("Q3Final");
body_start[10] = player.GetVar("Email1");
body_start[11] = player.GetVar("Q4");
body_start[12] = player.GetVar("Q4Final");
body_start[13] = player.GetVar("Q5");
body_start[14] = player.GetVar("Q5Final");
body_start[15] = player.GetVar("Q6");
body_start[16] = player.GetVar("Q6Final");
body_start[17] = player.GetVar("Q7");
body_start[18] = player.GetVar("Q7Final");
body_start[19] = player.GetVar("Q8");
body_start[20] = player.GetVar("Q8Final");
body_start[21] = player.GetVar("Q9");
body_start[22] = player.GetVar("Q9Final");
body_start[23] = player.GetVar("Q10");
body_start[24] = player.GetVar("Q10Final");
body_start[25] = player.GetVar("Q11");
body_start[26] = player.GetVar("Q11Final");
body_start[27] = player.GetVar("Q12");
body_start[28] = player.GetVar("Q12Final");
body_start[29] = player.GetVar("Q13");
body_start[30] = player.GetVar("Q13Final");
body_start[31] = player.GetVar("Q14");
body_start[32] = player.GetVar("Q14Final");
body_start[33] = player.GetVar("Q15");
body_start[34] = player.GetVar("Q15Final");
body_start[35] = player.GetVar("Q16");
body_start[36] = player.GetVar("Q16Final");
body_start[37] = player.GetVar("Q17");
body_start[38] = player.GetVar("Q17Final");
body_start[39] = player.GetVar("Q18");
body_start[40] = player.GetVar("Q18Final");
body_start[41] = player.GetVar("Q19");
body_start[42] = player.GetVar("Q19Final");
body_start[43] = player.GetVar("Q20");
body_start[44] = player.GetVar("Q20Final");
body_start[45] = player.GetVar("Q21");
body_start[46] = player.GetVar("Q21Final");
body_start[47] = player.GetVar("Q22");
body_start[48] = player.GetVar("Q22Final");
body_start[49] = player.GetVar("Q23");
body_start[50] = player.GetVar("Q23Final");
body_start[51] = player.GetVar("Q24");
body_start[52] = player.GetVar("Q24Final");
body_start[53] = player.GetVar("Q25");
body_start[54] = player.GetVar("Feedback1");
body_text = body_start[0]  +  body_start[1] + "%0D%0A" + body_start[2] + body_start[3] + "%0D%0A%0D%0A" + body_start[4]  + "%0D%0A" + body_start[5] + "%0D%0A%0D%0A" + body_start[6]  + "%0D%0A" + body_start[7]  +  "%0D%0A%0D%0A" + body_start[8]  + "%0D%0A" + body_start[9]  +  "%0D%0A%0D%0A" + body_start[11]  + "%0D%0A" + body_start[12]  +  "%0D%0A%0D%0A" + body_start[13]  + "%0D%0A" + body_start[14]  +  "%0D%0A%0D%0A" + body_start[15]  + "%0D%0A" + body_start[16]  +  "%0D%0A%0D%0A" + body_start[17]  + "%0D%0A" + body_start[18]  +  "%0D%0A%0D%0A" + body_start[19]  + "%0D%0A" + body_start[20]  +  "%0D%0A%0D%0A" + body_start[21]  + "%0D%0A" + body_start[22]  +  "%0D%0A%0D%0A" + body_start[23]  + "%0D%0A" + body_start[24]  +  "%0D%0A%0D%0A" + body_start[25]  + "%0D%0A" + body_start[26]  +  "%0D%0A%0D%0A" + body_start[27]  + "%0D%0A" + body_start[28]  +  "%0D%0A%0D%0A" + body_start[29]  + "%0D%0A" + body_start[30]  +  "%0D%0A%0D%0A" + body_start[31]  + "%0D%0A" + body_start[32]  +  "%0D%0A%0D%0A" + body_start[33]  + "%0D%0A" + body_start[34]  +  "%0D%0A%0D%0A" + body_start[35]  + "%0D%0A" + body_start[36]  +  "%0D%0A%0D%0A" + body_start[37]  + "%0D%0A" + body_start[38]  +  "%0D%0A%0D%0A" + body_start[39]  + "%0D%0A" + body_start[40]  +  "%0D%0A%0D%0A" + body_start[41]  + "%0D%0A" + body_start[42]  +  "%0D%0A%0D%0A" + body_start[43]  + "%0D%0A" + body_start[44]  +  "%0D%0A%0D%0A" + body_start[45]  + "%0D%0A" + body_start[46]  +  "%0D%0A%0D%0A" + body_start[47]  + "%0D%0A" + body_start[48]  +  "%0D%0A%0D%0A" + body_start[49]  + "%0D%0A" + body_start[50]  +  "%0D%0A%0D%0A" + body_start[51]  + "%0D%0A" + body_start[52]  +  "%0D%0A%0D%0A" + body_start[53]  + "%0D%0A" + body_start[54];

var mailto_link = "mailto:" + email + "?CC = " + body_start[10] + "&subject = " + subject + "&body  = " + body_text;
win = window.open(mailto_link, "emailWin");

20 Replies
Mike Cully

I copied all my questions and answer text into a Word document to get a character count for all 54 variables. Characters with no spaces = 1,356, Characters with spaces = 1,632. I don't think that's the issue. The fact that the trigger button stops working when I add in the 47 variable must mean there is some type of Articulate javascript limitation. Anyone from Articulate have any thoughts on this? Thanks!

Mike Cully

I did find a website that states:

"Storyline has got the characters limitation for adding javascript code into trigger window. You can add JS code in compiled/compressed state about 32,500 characters into a single trigger window. So that’s about 32kb of script."

http://www.electronmedia.in/wp/articulate-storyline-html5javascript-developers/

Not sure if this has anything to do with it. I'm definitely under on the character count for my javascript (3,700 - 4200 characters, 90 lines), but I'm not sure how to determine if it's over 32kb in size. The Word document is 15.4kb.

 

Jackson Hamner

Hey Mike,

So I don't know why your script worked with <46, but what I did was 2 things:

  1. Updated the body_Text so it has the var in front of it, I doubt this is what solved it
  2. removed all the spaces in your mailto call, which I suspect was the problem all along.

This got it working for me, I attached a .story file as an example.

The code that works for me:

var email = "any.email@youremail.com";
var cc = "body_start[10]";
var subject = "Configuration Report";
var player = GetPlayer();
var body_start = new Array();
body_start[0] = player.GetVar("Name");
body_start[1] = player.GetVar("FullName1");
body_start[2] = player.GetVar("City");
body_start[3] = player.GetVar("CityName1");
body_start[4] = player.GetVar("Q1");
body_start[5] = player.GetVar("Q1Final");
body_start[6] = player.GetVar("Q2");
body_start[7] = player.GetVar("Q2Final");
body_start[8] = player.GetVar("Q3");
body_start[9] = player.GetVar("Q3Final");
body_start[10] = player.GetVar("Email1");
body_start[11] = player.GetVar("Q4");
body_start[12] = player.GetVar("Q4Final");
body_start[13] = player.GetVar("Q5");
body_start[14] = player.GetVar("Q5Final");
body_start[15] = player.GetVar("Q6");
body_start[16] = player.GetVar("Q6Final");
body_start[17] = player.GetVar("Q7");
body_start[18] = player.GetVar("Q7Final");
body_start[19] = player.GetVar("Q8");
body_start[20] = player.GetVar("Q8Final");
body_start[21] = player.GetVar("Q9");
body_start[22] = player.GetVar("Q9Final");
body_start[23] = player.GetVar("Q10");
body_start[24] = player.GetVar("Q10Final");
body_start[25] = player.GetVar("Q11");
body_start[26] = player.GetVar("Q11Final");
body_start[27] = player.GetVar("Q12");
body_start[28] = player.GetVar("Q12Final");
body_start[29] = player.GetVar("Q13");
body_start[30] = player.GetVar("Q13Final");
body_start[31] = player.GetVar("Q14");
body_start[32] = player.GetVar("Q14Final");
body_start[33] = player.GetVar("Q15");
body_start[34] = player.GetVar("Q15Final");
body_start[35] = player.GetVar("Q16");
body_start[36] = player.GetVar("Q16Final");
body_start[37] = player.GetVar("Q17");
body_start[38] = player.GetVar("Q17Final");
body_start[39] = player.GetVar("Q18");
body_start[40] = player.GetVar("Q18Final");
body_start[41] = player.GetVar("Q19");
body_start[42] = player.GetVar("Q19Final");
body_start[43] = player.GetVar("Q20");
body_start[44] = player.GetVar("Q20Final");
body_start[45] = player.GetVar("Q21");
body_start[46] = player.GetVar("Q21Final");
body_start[47] = player.GetVar("Q22");
body_start[48] = player.GetVar("Q22Final");
body_start[49] = player.GetVar("Q23");
body_start[50] = player.GetVar("Q23Final");
body_start[51] = player.GetVar("Q24");
body_start[52] = player.GetVar("Q24Final");
body_start[53] = player.GetVar("Q25");
body_start[54] = player.GetVar("Feedback1");
var body_text = body_start[0] + body_start[1] + "%0D%0A" + body_start[2] + body_start[3] + "%0D%0A%0D%0A" + body_start[4] + "%0D%0A" + body_start[5] + "%0D%0A%0D%0A" + body_start[6] + "%0D%0A" + body_start[7] + "%0D%0A%0D%0A" + body_start[8] + "%0D%0A" + body_start[9] + "%0D%0A%0D%0A" + body_start[11] + "%0D%0A" + body_start[12] + "%0D%0A%0D%0A" + body_start[13] + "%0D%0A" + body_start[14] + "%0D%0A%0D%0A" + body_start[15] + "%0D%0A" + body_start[16] + "%0D%0A%0D%0A" + body_start[17] + "%0D%0A" + body_start[18] + "%0D%0A%0D%0A" + body_start[19] + "%0D%0A" + body_start[20] + "%0D%0A%0D%0A" + body_start[21] + "%0D%0A" + body_start[22] + "%0D%0A%0D%0A" + body_start[23] + "%0D%0A" + body_start[24] + "%0D%0A%0D%0A" + body_start[25] + "%0D%0A" + body_start[26] + "%0D%0A%0D%0A" + body_start[27] + "%0D%0A" + body_start[28] + "%0D%0A%0D%0A" + body_start[29] + "%0D%0A" + body_start[30] + "%0D%0A%0D%0A" + body_start[31] + "%0D%0A" + body_start[32] + "%0D%0A%0D%0A" + body_start[33] + "%0D%0A" + body_start[34] + "%0D%0A%0D%0A" + body_start[35] + "%0D%0A" + body_start[36] + "%0D%0A%0D%0A" + body_start[37] + "%0D%0A" + body_start[38] + "%0D%0A%0D%0A" + body_start[39] + "%0D%0A" + body_start[40] + "%0D%0A%0D%0A" + body_start[41] + "%0D%0A" + body_start[42] + "%0D%0A%0D%0A" + body_start[43] + "%0D%0A" + body_start[44] + "%0D%0A%0D%0A" + body_start[45] + "%0D%0A" + body_start[46] + "%0D%0A%0D%0A" + body_start[47] + "%0D%0A" + body_start[48] + "%0D%0A%0D%0A" + body_start[49] + "%0D%0A" + body_start[50] + "%0D%0A%0D%0A" + body_start[51] + "%0D%0A" + body_start[52] + "%0D%0A%0D%0A" + body_start[53] + "%0D%0A" + body_start[54];
var mailto_link = "mailto:" + email + "?CC=" + body_start[10] + "&subject=" + subject + "&body=" + body_text;
win = window.open(mailto_link, "emailWin");

I hope this helps!

Mike Cully

Ok, the plot thickens. If I use your code from above in my course and play back in IE 11 using Windows 7 Pro, the button doesn't work. If I play back within Firefox 37, the button works and the Outlook email client comes up, but it only displays partially through question 17. Your version of the javascript works, but it's using small existing data in your variables. I'm calculating the answers to display on four summary pages  with a series of triggers, maybe it has something to do with this process. I'm attaching a screen grab so you can see my triggers on page 3 of 4. (Everything display perfectly on the four summary screens). The button to submit by email is on page 4.

Jackson Hamner

I think I misread an earlier post of yours, im sorry for the confusion!

When I counted the characters in the email you generated in your previous post, and include the line breaks ("%0D%0A" , "%0D%0A%0D%0A") I got about 2000 characters. The mailto counts the final amount of characters being sent in, not the count of how long the variable names are.

So while your body_text variable might be <2000, because its value is full of reference variables it is in actuality going to be much longer than that.

For instance, if I had three variables I was sending through mailto, I would set it up like this:

var var1="This is an example"; //18 characters
var var2="This is a second example"; //25 characters
var var3="This is a third example"; //24 characters

var body_text = var1 + var2 + var3;
var mailto_link = "mailto:" + email + "&subject=" + subject + "&body=" + body_text;

Which means I am sending 67 characters through the mailto, instead of the 15 that is literally in the body_Text variable, because that is the sum of the characters from all of the reference variables (including spaces and line breaks).

When it reached question 17, it hit around 2000 characters and stopped sending it to your mail client. So you might need to cut down how much text you are sending to an email client.

Ashley Terwilliger-Pollard

Hi Mike and Jackson,

I just wanted to let you know I heard back from my team and the character count is confirmed at around 32,500. This is different than the limit to the mailto body property as that isn't something we control,  the mailto limit varies by browser and email client, so that would explain why your seeing differing behavior across browsers.

Hope that helps - and also just an FYI it looks like you replied via email and as such your signature is included here in the post. You're welcome to edit the post to remove that - but it's ok with us if you leave it. :) 

This discussion is closed. You can start a new discussion or contact Articulate Support.