Auto Approval using Workflow

Shreya Nagar
Tera Contributor

Hello ,

I am trying to get Auto Approval using condition based script in approval user activity If the caller is same as the approver , I 'm using below script but its not working and according to ServiceNow Community it should work. 

ShreyaNagar_0-1673602192716.png

 

 

3 REPLIES 3

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @Shreya Nagar ,

You can have the if activity along with run script activty. Please find the below code

If Activity

answer = ifScript();

function ifScript(){

if(current.request.opened_by == current.request.requested_for)

return 'yes';

else

return 'no';

}

Output of Yes to Run Script:

Run Script Below:

var gr = new GlideRecord('sysapproval_approver');

gr.initialize();

gr.sysapproval = current.sys_id;

gr.state = 'approved';

gr.approver = current.request.requested_for;

gr.comments = 'Auto approved';

gr.insert();
If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Omkar
Tera Contributor

One of the ways to achieve this is using Approval Action workflow activity.

After workflow activity, create a Run Script to evaluate if the caller is same as the approver, store the answer in scratchpad and based upon it utilize Approval Action activity.

Hey Omkar ,

Can you share me the script ?