- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 12:04 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2024 10:52 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 12:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 12:14 PM
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:
Please hit like and mark my response as correct if that helps.
Regards,
Sumanth Meda

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 12:24 PM
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.
Then if you successfully found that record, mark the RITM Approved.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2024 10:52 AM
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);