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

Paul, thanks this was great as the link is now being generated.   I do want the link to point to the Approval and note the Change itself however now it prints the same Change Number for each link.   My original notification email looked like this:


Original.jpg


I have modified the script to:


//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 ' + '${URI_REF}' + '</br>');


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


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


}



Now my notification e-mail looks like this:


Current.jpg


It makes sense that it's doing that, because the URI_REF is being generated from the record that triggered the notification.   You'll have to go the other route and manually build the URL...



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






//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.


Thank you very much Paul.   This worked and we do have users in California so I will account for that in the chg.work_start.   Great catch and thanks again for your help with this.


You're welcome.   I had never considered the idea of showing the CHG# but linking to the Approval record.   Very interesting, I just might have to go update my script now 🙂