Forum Discussion
Javascript in Storyline 360
I need to create a trigger that - when the learner clicks the Exit button - will automatically create and send an email that contains free-text survey results. There are two variables that need to be included: the learner's name (UserName), and the free-type entry (CalculatorText). This is the code I added:
var player = GetPLayer();
var email = "email@company.com";
var user = player.GetVar("UserName") ;
var text = player.GetVar("CalculatorText") ;
var subject = "Calculator quiz response" ;
var emailBody = "The response for\n" + user + "is:\n" + text;
var mailto_link = 'mailto: '+ email + '?subject=' + subject + '&body=' + encodeURIComponent (emailBody) ;
win = window.open(mailto_link, 'emailWin') ;
I've tested it in Review 360 and the Articulate Tempshare site, with no success. Any suggestions would be most welcome.
- MathNotermans-9Community Member
A few fixes to get this working. See the sample on Review...
https://360.articulate.com/review/content/d3c5d2eb-60ea-4474-914e-0cff915b0232/review
You need to be aware though that you have a proper default mail-client set on your computer...as that is what will be used. With Javascript you cannot test whether a user has a default mail client installed. If a user has not, 'mailto:' always fails.
This code works.var player = GetPlayer();
var email = "email@company.com";
var user = player.GetVar("UserName") ;
var text = player.GetVar("CalculatorText") ;
var subject = "Calculator quiz response" ;
console.log("mailto: "+user+" | "+text)
var emailBody = "The response for "+escape('\r\n') + user + " is: "+escape('\r\n')+"text";
var mailto_link = 'mailto: '+email+'?subject='+subject+'&body='+emailBody;
win = window.open(mailto_link, 'emailWin') ;
Notice the differences with your code...GetPlayer instead of GetPLayer.
Javascript is picky about capitals.
The emailbody line usesescape('\r\n')
and that part of code isnot included in a string... its outside the string. No need forencodeURIComponent
as escape already does that.
And here you have a complete working sample. Do use a external editor like Sublime Text or Brackets to edit your code. The Storyline ide doesnot show errors and really is no good. The tools mentioned all have colorcoding, hints and code checking. Makes life so much easier.
Kind regards,
Math- CindyBartrop-5dCommunity Member
Thanks so much - once I removed the quotation marks around "text", it worked perfectly!
Cheers,
Cindy Bartrop
Instructional Designer/
Documentation LeadrVox: 121-5608
direct: +1.778.331.5608
mobile: +1.604.315.6529
email: cbartrop@rbauction.com9500 Glenlyon Parkway
Burnaby, BC, CA V5J 0C6[cid:image001.png@01D7C5CD.CCD35B10]
Our Safety Commitment:
to send everyone home, every day,
the way they came to work[Macintosh HD:Users:seabay:Desktop:f-ogo
- WaltHamiltonSuper Hero
Depending on your browser, %0D%0A may work better than \n
Not sure what "no success" looks like, compared to what "success would look like, so I'm imagining that you mean nothing is happening. If that's the case, use the following Javascript debugging tool: alert ("message");
Place this anyplace in your js. If you see a message box with "message", the error is after the alert line. When js encounters an error, it stops at that point. Continually moving the Alert down through the script will allow you to isolate the line where execution fails.
One problem SL is known for is changing straight quotes and curly quotes. I don't know if that's a problem here, but dropping the script into Notepad, and copying it to the js pane, instead of entering it from the keyboard will cure that problem, if that's what it is.
- CindyBartrop-5dCommunity Member
Thanks - appreciate the help!
Cheers,
Cindy Bartrop
Instructional Designer/
Documentation LeadrVox: 121-5608
direct: +1.778.331.5608
mobile: +1.604.315.6529
email: cbartrop@rbauction.com9500 Glenlyon Parkway
Burnaby, BC, CA V5J 0C6[cid:image001.png@01D7C5CD.AAA9A0D0]
Our Safety Commitment:
to send everyone home, every day,
the way they came to work[Macintosh HD:Users:seabay:Desktop:f-ogo
- MathNotermans-9Community Member
Oops my mistake...indeed... its a variable....
Hi Cindy,
I'm glad that you were able to get the help you needed here.
It looks like your email signature came through when you replied via email. You can remove that if needed by clicking ‘Edit’ beneath your response. Here’s a quick Peek video if you need help.
- MargharitaNe202Community Member
I have this jarascript code in storyline, and I'm trying to eliminate the cc and bcc fields and customize the subject line to read: self-assessment results. Any help is greatly appreciated. I've been researching and trying different code, but given my limited knowledge of JS, nothing seems to work.
Player = GetPlayer();
var SendEmail = Player.GetVar("SendEmail")
var cc = Player.GetVar("carbonCopy")
var bcc = Player.GetVar("B_carbonCopy")
var Subject = Player.GetVar("EmailSubject")
var Primary = Player.GetVar("Primary");
var FirstName = Player.GetVar("Competing");
var LastName = Player.GetVar("Accommodating");
var StudentID = Player.GetVar("Compromising");
var StudentEmail = Player.GetVar("Avoiding");
var Student = Player.GetVar("Collaborating");
var sBody = "Your primary style: " + Primary + "\r\n\r\n";
sBody += "Competing: " + FirstName + "\r\n\r\n";
sBody += "Accommodating: " + LastName + "\r\n\r\n";
sBody += "Compromising: " + StudentID + "\r\n\r\n";
sBody += "Avoiding: " + StudentEmail + "\r\n\r\n";
sBody += "Collaborating: " + Student + "\r\n\r\n";
sBody = encodeURIComponent(sBody);
window.location.href = "mailto:" + SendEmail + "?cc=" + cc + "&bcc=" + bcc + "&subject=" + Subject + "&body=" + sBody; - WaltHamiltonSuper Hero
Delete these two lines:
var cc = Player.GetVar("carbonCopy")
var bcc = Player.GetVar("B_carbonCopy")Change this line:
var Subject = Player.GetVar("EmailSubject")
to:
var Subject ="self-assessment results"
Change this line:
window.location.href = "mailto:" + SendEmail + "?cc=" + cc + "&bcc=" + bcc + "&subject=" + Subject + "&body=" + sBody;
to:
window.location.href = "mailto:" + SendEmail + "?subject=" +Subject + "&body=" + sBody;
If the JS is otherwise good, those changes will give you what you want.