Prevent Approval from requestor - Requested Item

Richo1
Tera Expert

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

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

HI @Richo1 ,
I trust you are doing great.

Here's the proposed solution:

  1. Open the catalog item in ServiceNow.
  2. Go to the flow designer for the 'Ask for approval' flow.
  3. Edit the flow and navigate to the 'Approvals' section.
  4. 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



Hi Amit,

 

I have attached a screen shot of my current approval flow. Just wanted to know where I would add the java script?

 

Thanks.