Prevent Approval from requestor - Requested Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 07:58 PM
Hello,
I have a catalog item, which goes to group approval when the requested item is created. I want to prevent a requestor who is part of the approval group from approving their own requested items. I'm currently using flow 'Ask for approval'
I currently have it set to be approved if anyone in the group approves the requested item.
Thanks,
Richo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 10:38 PM
HI @Richo1 ,
I trust you are doing great.
Here's the proposed solution:
- Open the catalog item in ServiceNow.
- Go to the flow designer for the 'Ask for approval' flow.
- Edit the flow and navigate to the 'Approvals' section.
- Modify the existing approval condition to exclude the requestor from the approval group.
To implement this change, we can use ServiceNow's built-in scripting capabilities. Here's an example of how the code could be written in Javascript:
// Get the current user and their approval groups
var currentUser = gs.getUser();
var approvalGroups = currentUser.getMyGroups();
// Get the requested item
var requestedItem = current.item; // Assuming 'current' is the current record
// Check if the requestor is part of any approval group
for (var i = 0; i < approvalGroups.length; i++) {
var approvalGroup = approvalGroups[i];
// Compare the requestor's user ID with the approval group members
if (approvalGroup.isMember(currentUser.getID())) {
// Prevent the requestor from approving their own requested items
if (requestedItem.opened_for == currentUser.getID()) {
current.approval = 'rejected'; // Set the approval status to 'rejected'
break; // Exit the loop, as we don't need to check further
}
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 04:04 PM