Javascript for email not including subject line

Can anyone help? I've adapted javascript from a previous thread on here. It triggers the email and the content correctly but the subject line is missing. I don't know what I'm doing wrong. Here's my script:

var player = GetPlayer();

var useremail=player.GetVar("email");

var subject="Training Claims";

var exercisenotes1=player.GetVar("Thoughts1");
var exercisenotes2=player.GetVar("Thoughts2");
var exercisenotes3=player.GetVar("Thoughts3");

var mailto_link='mailto:'+useremail+'?subject='+subject+'&body='+"Fault Claim Number:%0d%0A"+exercisenotes1+"%0d%0A%0d%0ANon Fault Claim Number:%0d%0A"+exercisenotes2+"%0d%0A%0d%0ANotification Only Claim Number:%0d%0A"+exercisenotes3;

win=window.open(mailto_link,'emailWin');

 

2 Replies
Christie Pollick

Hi, Andrea -- Many thanks for reaching out!  JavaScript is not something for which we are able to offer support, but there are many who are knowledgeable in JS coding here in the community who are usually more than happy to assist! And in case you'd like to take a look, here is our JS Best Practices sheet. :)

Matthew Bibby

Hi Andrea, 

Give this a try instead:

var player = GetPlayer();
var email = player.GetVar("Email");
var fault = player.GetVar("Fault");
var nonFault = player.GetVar("Non_Fault");
var notificationOnly = player.GetVar("Notification_Only");
var subject = "Training Claims";
var emailBody = "Fault Claim Number:\n\n" + fault + "\n\nNon Fault Claim Number:\n\n" + nonFault + "\n\nNotification Only Claim Number:\n\n" + notificationOnly;
emailBody = encodeURIComponent(emailBody);
var mailto_link='mailto: '+email+'?subject='+subject+'&body='+emailBody;
win=window.open(mailto_link,'emailWin');

This assumes you have the following text variables set up in Storyline:

Email
Fault
Non_Fault
Notification_Only

Here is a demo and here is the source file.