Java Script Email

Hello,

 

I am trying to create a JavaScript code where it pulls in the colleague's name (EEName) and am trying to send a hyperlink through the body of the email.

 

Can someone who is familiar with JS check over this code and see if this looks accurate? Any help would be appreciated as I am not that familiar with JS.

 

Thanks!

 

 

var EEName = player.GetVar('EEName');
var player = GetPlayer();
var email = player.GetVar('MgrEmail');
var subject = 'Your Offboarding Checklist for ' + 'EEName';
var emailBody = 'Hello' + '\n' + 'Please see your offboarding checklist for ' + 'EEName' + '\n' + 'https://thezone.corp.zoetis.com/hrforme/USA/_layouts/15/WopiFrame.aspx?sourcedoc={8BFB842F-3611-4BE9-8ECB-39C6B68A31A8}&file=Manager%20Separation%20Checklist_rev3_28_18.docx&action=default';
window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);

9 Replies
Matthew Bibby

Try this instead:

var player = GetPlayer();
var email = player.GetVar('MgrEmail');
var name = player.GetVar('EEName');
var url = 'https://thezone.corp.zoetis.com/hrforme/USA/_layouts/15/WopiFrame.aspx?sourcedoc={8BFB842F-3611-4BE9-8ECB-39C6B68A31A8}&file=Manager%20Separation%20Checklist_rev3_28_18.docx&action=default';
var subject = 'Your Offboarding Checklist for ' + name;
var emailBody = 'Please see your offboarding checklist for ' + name + '.' + '\n\n' + url;
window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);
Matthew Bibby

This won't work when you are previewing the course. You'll need to publish it and test in its intended environment. 

I've just tested the CD output here and it seems to work as expected.

Review is a bit different. While I could get the email to generate when using a desktop email client, I ran into issues when a web-based email client was used.

Try this demo.

Re your variables, just make sure that are called MgrEmail and EEName 

Kevin Merendino

Eureka !! I was able to figure it out :)

So I forgot that I created duplicated pages with the the incorrect line below and I'm assuming that is why it wasn't working.

Also, why would this code be an error? I do want to send other custom emails with URL's and other verbiage so just so I can create these other emails with ease it would be good to know some best practices when creating a custom email body with JS.

 

Thanks for your help!

 

var emailBody = 'Hello' + 'Here is your offboarding checklist to help with a smooth offboarding for' + EEName:' + '\n' + fbk;

 

Matthew Bibby
Kevin Merendino

So I forgot that I created duplicated pages with the the incorrect line below and I'm assuming that is why it wasn't working.

Also, why would this code be an error? I do want to send other custom emails with URL's and other verbiage so just so I can create these other emails with ease it would be good to know some best practices when creating a custom email body with JS.

I don't know why that line of code caused an error, it's hard to say without seeing the rest of the code. If you want to learn more about creating emails in this way, see here.