How to Auto approve a request if opened by is manager

subhyde
Giga Contributor

Hello,

 

As of now our platform just has a check to see if the request was opened by the requested for's manager and it skips the approval and sets the state as approved

 

What I am looking to do is actually show the manager in the approval tab in the request but have it auto-approved. instead of there being no approvers present.

 

It will function the same. it is more of a cosmetic change to show that the request was actually approved, even though it will be automatic

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you could use combination of if + run script activity

Assuming this is for Catalog Item workflow

If Activity

answer = ifScript();

function ifScript(){

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

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.manager;

gr.comments = 'Auto approved';

gr.insert();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Michael Kaufman
Giga Guru

I would insert an "approved" approval using workflow.

Activity 1: If Statement

If: Opened By is Manager
Condition: Opened By is same as Request.Requested for.Manager

If yes run activity 2.

Activity 2: Run Script
Run Script: Generate Approval
(function() {
var grApproval = new GlideRecord("sysapproval_approver");
grApproval.initialize();
grApproval.setValue('sysapproval',current.sys_id);
grApproval.setValue('approver',current.opened_by);
grApproval.setValue('state','approved');
grApproval.comments('Auto Approved');
grApproval.insert();
})();

If no, do regular approvals

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you could use combination of if + run script activity

Assuming this is for Catalog Item workflow

If Activity

answer = ifScript();

function ifScript(){

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

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.manager;

gr.comments = 'Auto approved';

gr.insert();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

which type of the script used?