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.

Mail Script URI Link Help

shawhan1126
Giga Contributor

I have the following mail script for Change Approval Reminders:

//First, we need to locate our current user's approvals (the parm1 variable contains the current approver)

var app = new GlideRecord('sysapproval_approver');                           //create a query to retrieve open approvals

app.addQuery('state','requested');                                                                             //only retrieve approvals that are pending

app.addQuery('approver',event.parm1);                                                             //only find approvals for the current approver

app.addQuery('sysapproval.sys_class_name','change_request');                     //only find approvals for change reqeusts

app.query();

while(app.next()){

//now that we have an approval for that user, we are going to look up the change tickets they need to approve and print out the data

var chg = new GlideRecord('change_request');                                     //find the first related Change approval and print info

chg.get(app.sysapproval);

template.print('<p>You have an open change approval for ' + chg.number + '</br>');

template.print('<b>Description:</b> ' + chg.short_description + '</br>');

template.print('<b>Scheduled date:</b> ' + chg.work_start + '</p>');

}

I would like to make the chg.number a clickable link.   I am unable to do so with ${URI_REF}.   I would rather not have a separate link that says click here and instead have the CHG number itself clickable (Screenshot below).   Any help?

Screenshot.jpg

1 ACCEPTED SOLUTION

//I do want the link to point to the Approval and note the Change itself //



I just noticed this.   So the link needs to be...



template.print('<p>You have an open change approval for <A href="https://yourinstance.service-now.com/nav_to.do?uri=sysapproval_approver.do?sys_id=' + app.sys_id + '">' + chg.number + '</a><BR>');






One little detail...I think chg.work_start   should be chg.work_start.getDisplayValue() so that it accounts for user time zone.   Not sure if this is relevant to you, if you have people in different time zones.


View solution in original post

10 REPLIES 10

justin_drysdale
Mega Guru

Assuming you can pass the sys_id along with the change number, you can use a function to build the link:



//First, we need to locate our current user's approvals (the parm1 variable contains the current approver)


var app = new GlideRecord('sysapproval_approver');                           //create a query to retrieve open approvals


app.addQuery('state','requested');                                                                           //only retrieve approvals that are pending


app.addQuery('approver',event.parm1);                                                           //only find approvals for the current approver


app.addQuery('sysapproval.sys_class_name','change_request');                   //only find approvals for change reqeusts


app.query();


while(app.next()){


//now that we have an approval for that user, we are going to look up the change tickets they need to approve and print out the data


var chg = new GlideRecord('change_request');                                   //find the first related Change approval and print info


chg.get(app.sysapproval);


template.print('<p>You have an open change approval for ' + buildLink(chg.number.toString(), chg.sys_id.toString()) + '</br>');


template.print('<b>Description:</b> ' + chg.short_description + '</br>');


template.print('<b>Scheduled date:</b> ' + chg.work_start + '</p>');



function buildLink(n, sid) {


  var s = 'https://YOURINSTANCE.service-now.com/';


          s += 'nav_to.do?uri=change_request.do%3Fsys_id=';


          s += sid;


  var link = "<a href='" + s + "'>" + n + "<\a>";


  return link;


}


}