how to create auto approval in ServiceNow flow designer if requester is one of approver.

KV_PraveenKumar
Tera Expert

how to create auto approval in ServiceNow flow designer if requester is one of approver.

 

My requirement has 2 level approvals,

1 level will be requested for manager approval and

2.it will be owners' approval where there is a possibility requester is one of approver 

1 ACCEPTED SOLUTION

KV_PraveenKumar
Tera Expert

@Sumanth16 , 

@JenniferRah 

@Najmuddin Mohd 

 

Thanks for coming forward to help me, somehow i figured out workaound for this,

 

The requirement was,

for a catalog it suppose to have 2 leve approvals, 1st one will be requested for > manager and the second one will based on owners variable, which contains multiple users.

here  there is a probability that requested by may come as owner, in that situation second level approval shoul auto approve .

 

I've achieved  this with the help of action called "Script".

 

I have created a action and selected Script as step. and provided input variables as opened by and Owners.

and the logic used "Owners  Includes opened by"

1.if it returns false then goes ahead create 2nd level approval for all owners. 

2. if it returns true then it creates an approval record with state approved and approver as opened by.

 

Below script i have used

 

(function execute(inputs, outputs) {

   

    // Extract the `openedby` sys_id

    var openedbySysId = inputs.openedby;

   

    // Extract the `owners` array of sys_ids (assuming it's a string of comma-separated sys_ids)

    var ownersArray = inputs.owners.split(',').map(function(id) {

        return id.trim();

    });

 

    if (ownersArray.includes(openedbySysId)) {

        //gs.info("Opened by user is one of the owners.");

        outputs.owner = true;  // Return true if the openedby user is one of the owners

    } else {

        //gs.info("Opened by user is NOT one of the owners.");

        outputs.owner = false;  // Return false if the openedby user is not in the owners list

    }

 

})(inputs, outputs);

View solution in original post

5 REPLIES 5

ying_han
ServiceNow Employee
ServiceNow Employee

You can also use a before Business rule on sysapproval_approver table, check if

approval for's task type is req_item &

approval for's item is <the catalog item> &

approver = approval for.requested item.requested_for & 

state=request

 

if matches, set state to approved

ying_han_0-1756094882567.png

ying_han_1-1756094891246.png