Script Syntax for adding URL link in email script

Shawn Horley
Kilo Guru

Greetings Folks

Our Service Portal goes live in Two Weeks (YAY!) so we want to include a link to the splash page that we have in place so Our Users can see what it looks like, and start to get used to the idea of having a service portal. My challenge is I am still rubbish at scripting and code and am looking for the proper syntax to get the URL link into our email notification.

The link needs to be part of a sentence, like this:

Lights...Camera...Action! (link to portal) is coming soon!

I know I could use the Variables in the Notifications, but they want this to exist within the already existing scripts so that it has the same fonts, look/feel etc, and to not look "bolted on" to the notification as it were.

I've looked at articles like these:

https://community.servicenow.com/community?id=community_question&sys_id=37bc8fe5db9cdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=79d187a9db98dbc01dcaf3231f96...

But they are about links for specific forms, and I am too much of a Code Noob to understand if I can modify what I am reading in those posts.

Can anyone provide me the syntax I would need to add in an email script to make that sentence work?

Cheers

A.

1 ACCEPTED SOLUTION

Himanshu Rawat4
Giga Guru

Hi A,

You have to do 2 things, first is the 

1. Create a new email script:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Add your code here
var url= <<your portal url>>;
template.print('<a href=' + url + '>Portal link </a' );
})(current, template, email, email_action, event);

2. Go to the notification HTML message, add

Lights...Camera...Action! ${mail_script:<<name of the script you created in step>>} is coming soon!

${mail_script:<<name of the script you created in step>>} - responsible to show the url in the mail

Let me know if it helps.

Thanks,

Himanshu.

View solution in original post

2 REPLIES 2

Himanshu Rawat4
Giga Guru

Hi A,

You have to do 2 things, first is the 

1. Create a new email script:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Add your code here
var url= <<your portal url>>;
template.print('<a href=' + url + '>Portal link </a' );
})(current, template, email, email_action, event);

2. Go to the notification HTML message, add

Lights...Camera...Action! ${mail_script:<<name of the script you created in step>>} is coming soon!

${mail_script:<<name of the script you created in step>>} - responsible to show the url in the mail

Let me know if it helps.

Thanks,

Himanshu.

Shawn Horley
Kilo Guru

Greetings Himanshu!

Thank you very much for your response!  That was what I needed!

I cheated a bit as I threw the code right into the existing script rather than referencing from a variable, so it looks like this (lines 11 and 12):

 

//Script for notification to caller that Email was received 
(function runMailScript(current, template, email, email_action, event) {
	email.setSubject("Your message: " + current.short_description + " has been received ") ;
	template.print('<p><font size="5" color="#808080" face="Calibri"><strong>');
    template.print("Hello " + current.caller.first_name +",");
    template.print('</strong></font></p>');
    template.print('<p><font size="3" color="#808080" face="Calibri"><strong>');
    template.print("Your message for IT Support: <i>" + current.short_description + "</i> has been received, and you will receive a ticket number shortly. Please do not respond to this message.");
	template.print('</strong></font></p>');
	template.print('<p><font size="3" color="#808080" face="Calibri"><strong>');	
	var url='http://portal link/';
	template.print('Lights...Camera...Action!'); template.print('<a href="'+url+'"> Portal Link </a>'); template.print('is coming soon!');
	template.print('</strong></font></p>');
})(current, template, email, email_action, event);

and it works perfectly!

Thank you for your instruction, as I had no idea what the syntax was for what I was needing!

Cheers!

Arthwys