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
Hi Mike,
I haven't seen anything that would limit the number of variables or elements with the Javascript, but I'd defer to the community's expertise there. In the meantime you may want to begin by reviewing the information in regards to Javascript best practices here.
Do you mean the email body stops after the 46th variable?
If so, mailto has a character limit, and that may be your problem. Depending on your browser you can get a max of ~2000 characters into the email body, so if you plan to email something you need to make sure its under that amount of characters.
Thanks for the feedback Jackson. What happens is the button trigger won't even work once I add in more that 46 variables in the Javascript. If I leave it at 46, the button works and triggers the email client to come up, if I add in 47 to the script, the button does not work. Very odd...
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!
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.
I believe you have an error in the second half of your code, which in storyline will prevent any of your javascript in the trigger from running.
Your body_text variable doesn't get set as a variable,
That should be var body_text
I think that might fix it, let me know if it starts working :)
Hi Mike,
I haven't seen any official documentation regarding a character count limit, but I'll reach out to our team to confirm.
Jackson, I changed it to var body_text then went through all the questions and the button doesn't work. When I only had up to variable 46, I had it as body_text and the button worked. It must be something else. Thanks for the suggestion!
Hey Mike,
So I don't know why your script worked with <46, but what I did was 2 things:
This got it working for me, I attached a .story file as an example.
The code that works for me:
I hope this helps!
Thanks Jackson! I'll check it out and let you know if it works...
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.
Thanks for your continued assistance Jackson :)
Leslie, any thoughts from the Articulate team as to why this might be happening?
Hi Mike - I'm still waiting for confirmation from our team regarding a character limit, but I hadn't found one in my search.
Would you mind posting the email that stopped part way through Q17 for me?
Hey Jackson, how should I post it? If you sent me an email I could forward it to you...
This post was removed by the author
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:
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.
Great detective work Jackson! Still confused why IE doesn't work at all, and if I remove Q47-54 from the JavaScript code, I can get up to Q21 in IE.
Thank you for all your help!
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. :)
Thanks Ashley!
This discussion is closed. You can start a new discussion or contact Articulate Support.