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

Najmuddin Mohd
Mega Sage

HI @KV_PraveenKumar ,

Can you please elaborate a little bit. 
If the Requestor is not approver, then there is no second level of approval ?
And if it is, which record's owner will the approval will be triggered ?

Regards,
Najmuddin.

Sumanth16
Kilo Patron

Hi @KV_PraveenKumar ,

 

You will need to evaluate if the flow should go into the approval or not, using an IF flow logic.

Something like below:

Sumanth16_0-1729883568111.png

Please hit like and mark my response as correct if that helps.


Regards,

Sumanth Meda

 

 

JenniferRah
Mega Sage

After your first approval, look up the manager in the sys_user_grmember table to see if he's a member of the group you are about to request access from. Make sure you check the "Don't fail on error" checkbox.

JenniferRah_0-1729884107447.png

Then if you successfully found that record, mark the RITM Approved.

JenniferRah_1-1729884167435.png

 

If you aren't going to do a group approval as your second approval, just look up the user in whatever table you are looking for the approver and use the same method.

 

You can also create a Flow Variable and script the lookup and comparison if you want, but this is a lower code 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);