How can I get the sys_id of an approver within a workflow?

kent_harwell
Giga Contributor

Can someone please tell me how to store the sys_id of an approver into g_scratchpad?

I need to save the sys_id of the person that approved an "Approval - User" activity in a workflow to use later in the same workflow.

2 REPLIES 2

AbhishekGardade
Giga Sage

Hello Kent,

Add below code in approver activity or any of the activity and then using workflow scratchpad you can access it,

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval','current.sys_id');
gr.query();
if(gr.next()){

workflow.scratchpad.approvarName = gr.approver;
gs.print("Approver SYS ID:"+gr.approver+"Approvar Name:"+gr.approver.name);

}

find_real_file.png

Workflow scratchad :

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/using-workflows/conc...

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Hello Kent,

If you have more than one approvars then use below script:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval',current.sys_id);
gr.query();
var approvers =[];
while(gr.next()){
approvers.push(gr.approver.toString());
gs.log("Approver SYS ID:"+gr.approver+"Approvar Name:"+gr.approver.name);

}

workflow.scratchpad.approvarName = approvers;
gs.log("All the approvers:"+approvers);

Thank you,
Abhishek Gardade