- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 08:49 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 10:01 AM
//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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 08:55 AM
Hi Shawhan,
<a href="<mail_script>template.print(gs.getProperty('glide.servlet.uri'))</mail_script>/change_request.do?sys_id=${sys_id}" >change number</a>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 09:00 AM
That ${sys_id} will be the sys_id of the Approval record that triggered the notification. You'd have to make it ${sysapproval.sys_id} for it to be the sys_id of the Change Request. Also, because he is doing this inside a query inside a script, not inside a Notification, the <mail_script> syntax won't work. It would have to be:
template.print('<A href="' + gs.getProperty('glide.servlet.uri') + '/change_request.do?sys_id=${app.sysapproval.sys_id}">${app.sysapproval.number}</a>');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 09:03 AM
Thanks Paul, its was a good catch.
I just emphasized on creating the link
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 08:56 AM
Well the first thing I would say is you don't need the second nested query. You can dotwalk to the Change fields. Instead of the query and:
template.print('<b>Description:</b> ' + chg.short_description + '</br>');
...eliminate the query and use:
template.print('<b>Description:</b> ' + app.sysapproval.short_description + '</br>');
As for how to use URI_REF, this should work:
template.print('${sysapproval.URI_REF}')
Notice it is inside the quotes. What I have found is that the mail script outputs the literal text to the notification, which then processes any remaining $ expressions. So think of the ${sysapproval.URI_REF} expression as if you had entered it directly into the Notification, rather than from the context of the script.
