yes, you need to add run script activity after approval activity.

First you need to run script to get correct approval record after after approval activity. Also, you need to add timer after approval activity finishes 

 

you can use below

 

var arr=[];

 

var gr= new GlideRecord('sysapproval_approver');

 

gr.addQuery('sysapproval',current.sys_id);

 

gr.query();

 

while(gr.next()){

 

arr.push(gr.getValue('sys_id')); //this will contain all the sys_id

 

}

 

Regards,

Sachin

Sachin, unfortunately your suggestion won't work. Jerin wants to add a comment to the approval as that approval is created.  As you know workflows will pause on Approval activities and remain on them until the approval has been approved or rejected so your suggestion of a run script AFTER this activity will update the approval too late.

What I ended up doing is creating a branch. One branch goes to the approval activity, the second branch goes to a run script. Then I joined the 2 activities.

Initially, I had a timer, but I was noticing that the comment would be after the initial notification for approval went, so I removed the timer. 

I also wanted to add the requested_for as part of the comment which is why there are 2 glide record queries. I know it's clunky, but here is the code I used:

//Get value for Requested for user and pass to variable reqFor
var gr_req = new GlideRecord ('sc_req_item');

gr_req.addQuery('sys_id', '168251121b8fc410c19321fcbc4bcbd3');
gr_req.query();
gr_req.next();
var reqFor = gr_req.variables.service_recipient_name.getDisplayValue();

// Get Sys approval record for Supervisor Approval
var gr= new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval',current.sys_id);
gr.query();

//Add commment to Supervisor approval record
while(gr.next()){
var a = gr.wf_activity.getDisplayValue();
if (a == 'Supervisor Approval'){
gr.comments.setJournalEntry("Please acknowledge that you are approving local admin permissions for " + reqFor, 'admin');
gr.update();
}
}

 

Screenshot of Workflow:

find_real_file.png

Wel... I am listening to @Chuck Tomasi  on JavaScript for ServiceNow for Glide Records (https://www.youtube.com/watch?v=hAm0_-ak65c&list=PL3rNcyAiDYK2_87aRvXEmAyD8M9DARVGK&index=28) and finding how I could have changed the above code...

Using .getValue instead of dot walking and using .get instead of using Query 😞

Kevin133
Tera Expert

Maybe i'm not understanding the requirement but cant you just add ${comments} or ${sysapproval.comments} to your notification template for your approval notification?