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.

Help with approval link.

nkpanesar
Kilo Contributor

Hello All,  I need help in generating link to the approval page.

Below is What I have done so far, but I get "record not found" everytime I click on "this link".Seems like its picking wrong sysid, but need guidance how to get this working.

Requirement:

Approver gets email with link to approve a given RITM, this link should take him to the approval page. I have Admin rights, so its not a permission issue.

find_real_file.png

When I click on "This link" Getting Record could not be found.

find_real_file.png

The Script that generates the link is below:

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

var url = 'https://'+ gs.getProperty("instance_name") +'.service-now.com/biomarin_sp?id=approval&table=sysapproval_approver&sys_id='+current.sys_id;
template.print('<a href='+url+'>this link</a>');

})(current, template, email, email_action, event);

The notification that triggers this script is defined in the WF itself:

find_real_file.png

find_real_file.png

5 REPLIES 5

In the mail script you could query the sysapproval_approver table for an active approval for the RITM,

 

var approvalGR = new GlideRecord('sysapproval_approver');

approvalGR.addEncodedQuery('state=requested^sysapproval=' + ritm.sys id'); //assuming this is current then current.sys_id

approvalGR.query('approver', user_id, event.parm1?2?) //this lets you pinpoint in case you have multiple for the RITM

approvalGR.query();

 

if(approvalGR.next()){

//if only one then get the sys id of approvalGR, if multiple you an construct your url with multiple sys_id=id^ORsys_id=id  : etc

}