Forum Discussion
Javascript for sending Storyline 360 text entries via email
Within SL, I've been trying to initiate an email via javascript that contains text entry content, but I cannot get it to work. Essentially, I want the learner to be able to send their notes to themselves/others in an email.
I get halfway there: I'm able to generate a new browser tab (via each of the below separate sets of java), but no Outlook email generates. Each of them, when tested separately, only opens a Chrome browser tab.
What am I doing wrong? I need it to generate an Outlook email.
JAVA 1
var player = GetPlayer();
var email='';
var subject='Tracks Course Notes';
var feedback=player.GetVar('MyNotes');
var emailBody = +feedback
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);
win=window.open(mailto_link,'emailWin');
--------------------------
JAVA 2
var player = GetPlayer();
var useremail=player.GetVar("Email");
var subject="Tracks Training Notes";
var notes1=player.GetVar("MyNotes");
var content="Tracks Training Notes%0d%0A%0d%0A";
content+=notes1;
var mailto_link='mailto:'+useremail+'?subject='+subject+'&body='+content;
win=window.open(mailto_link,'emailWin');
-------------------------------
JAVA 3
var player = GetPlayer();
var email=player.GetVar("Email");
var subject="Tracks Training Feedback";
var body_start=player.GetVar("MyNotes");
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+escape(body_start);
emailwin=window.open(mailto_link,'emailWin');
emailwin=window.close();
- JoeFrancisCommunity Member
There's a term for a script running inside of a web browser which forces an application on the client desktop to launch, without the user's approval. It's called "malware."
- MathNotermans-9Community Member
Without a sample...this is more a puzzle then anything else. Please add a sample...then someone can help you quickly.
- ShaeZeitzCommunity Member
- MariaCSStaff
Hi, Shae.
Thank you for sharing the .story file!
This is likely related to your computer's default mail application. It worked for me using both Outlook and Mail:
I hope this helps!
- TomWasieleskiCommunity Member
Hi Maria! For some reason, I can't see your screen recording - can you try uploading it again? I'm trying to do the same thing as Shae, and it'd be great to figure this out. :) I've added my current .story file so you can see the JavaScript in there (I know nothing about JavaScript!).
Thank you!
- ShaeZeitzCommunity Member
Maria, you are amazing! Thank you for your help. It's working for me now.
- MariaCSStaff
Hi, Shamina.
Thank you for letting me know! I fixed the link, and you should be able to see the screen recording now.
Since I'm not very knowledgeable in Javascript, and it's not something we support, I'll leave it for our community members to chime in. However, I noticed your code referenced variables that were not in your project.
I changed a few things, and it looks like it's working now. I'm attaching the .story file here.
I hope this helps!
- DevanAbiaCommunity Member
This is great! It worked like a charm for me. How would I adjust JavaScript so that multiple text variables could be added to the body of the email rather than one?
I tried adding a ‘TextEntry4’ after ‘Reflections’ but it didn’t work.
- JanetMinchel681Community Member
Anyone know how to make this javascript open in Outlook so learners can ask questions? Here is my current JS
var player = GetPlayer();
var email='';
var subject='VCI Complaint Management Question';
var feedback=player.GetVar('MyQuestion');
var emailBody = +feedback
var mailto_link='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);
win=window.open(mailto_link,'regulatorytraining@vwcredit.com'); - FaffieKhanCommunity Member
- AdamFrager-30a0Community Member
HI all,
By any chance did anyone figure out how to force the script to open Outlook over the System default?
I can't expect my learners to change their system mail default.
Thank you in advance- MathNotermans-9Community Member
You cannot force any other mail client than the default.
If the users default mail client will not work for you, you can use a smtp mail server to send the mail directly. More complicated though to get working.
- SaraCollisterCommunity Member
Hi, I'm able to bring over the text entry into the email body but it loses all formatting and merges into one long line of continuous text. Does anybody know how to bring over the formatted texts/keep the paragraphs?
Any help is appreciated. TIA :)
My current JS -
var player = GetPlayer();
var email='';
var user = player.GetVar("UserName") ;
var text = player.GetVar("TextEntry") ;
var subject = "Journal Exercise Notes" ;
console.log("mailto: "+user+" | "+text)
var emailBody = player.GetVar("TextEntry");
var mailto_link = 'mailto: '+email+'?subject='+subject+'&body='+emailBody;
win = window.open(mailto_link, 'emailWin') ;