Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dynamically create URL in Email Notifications

tkh
Kilo Expert

We have some users who interact with SerivceNow via a separate web portal.   Management from the other portal has requested that the notifications for companies that use the other web portal use a URL for that portal.  So we have a check box on the companies that use the other web portal.

 

The ask is that for notifications if the "u_in_portal" is true the URL look something like https://portal.com/ticket_type/[sys_id]

the if "u_in_portal" is false use the regular ServiceNow URL to the record

Is there a way to dynamically add the URL to the email notification based on the "u_in_portal" filed on the company page?

1 ACCEPTED SOLUTION

tkh
Kilo Expert

Final solution

 

var num = current.sys_id; //quick easy grab of current record sys_id to use in building URL

var gr = new GlideRecord('change_request'); //New glideRecord on change_request table
gr.addQuery("sys_id", num); //Limits the record look up to just the current record sys_id
gr.query(); //executes the query
while (gr.next()); //while there is a next record (esentially for each record found) do the following

//If the check box is true (checked)
if (gr.u_checkbox == true){

//Start of string sentence to show in the email body
template.print("More details can be found ");

//create variable to incld the part of the URL that will remain constant + the current sys_id variable from above (num)
var pLink = "https://company.com/subsite/support/#/editChangeRequest/" + current.sys_id;

//create html anchor (<a href) to create the actual URL link using the word here as the text link
var pAnchor = "<a href='" + pLink +"'>" + "here." + "</a>";
template.print(pAnchor + "<br />");
}

//If the \check box ix false (not checked) then the URL link will be created the same way as above, but will link back to the record in ServiceNow
if (gr.u_checkbox == false){
template.print("More details can be found ");
var sLink = "https://instance.service-now.com/nav_to.do?uri=change_request.do?sys_id=" + current.sys_id;
var sAnchor = "<a href='" + sLink +"'>" + "here." + "</a>";
template.print(sAnchor + "<br />");
}

View solution in original post

5 REPLIES 5

tkh
Kilo Expert

Final solution

 

var num = current.sys_id; //quick easy grab of current record sys_id to use in building URL

var gr = new GlideRecord('change_request'); //New glideRecord on change_request table
gr.addQuery("sys_id", num); //Limits the record look up to just the current record sys_id
gr.query(); //executes the query
while (gr.next()); //while there is a next record (esentially for each record found) do the following

//If the check box is true (checked)
if (gr.u_checkbox == true){

//Start of string sentence to show in the email body
template.print("More details can be found ");

//create variable to incld the part of the URL that will remain constant + the current sys_id variable from above (num)
var pLink = "https://company.com/subsite/support/#/editChangeRequest/" + current.sys_id;

//create html anchor (<a href) to create the actual URL link using the word here as the text link
var pAnchor = "<a href='" + pLink +"'>" + "here." + "</a>";
template.print(pAnchor + "<br />");
}

//If the \check box ix false (not checked) then the URL link will be created the same way as above, but will link back to the record in ServiceNow
if (gr.u_checkbox == false){
template.print("More details can be found ");
var sLink = "https://instance.service-now.com/nav_to.do?uri=change_request.do?sys_id=" + current.sys_id;
var sAnchor = "<a href='" + sLink +"'>" + "here." + "</a>";
template.print(sAnchor + "<br />");
}