How to avoid duplicate approvals

srinath1391
Tera Contributor

Hello Team,

 

Scenario: There are parallel approvals one is user approval another is group approval,

In user approval user as static called  "A" person

and same "A" person present in X group, group is dynamic based on the selection on the form 

 

Sometimes approvals are triggering double to the A person through user approval and group approval.

 

How avoid these duplication please suggest.

 

Thanks in Advance.

 

Regards,

Srinath.

6 REPLIES 6

Robbie
Kilo Patron
Kilo Patron

Hi @srinath1391,

 

This is an oldie and goodie, check this link from SNGuru to prevent multiple approvals.

It has a clear explanation of what to do and how to write a business rule to prevent multiple approvals.

 

Prevent Multiple Approvals

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

Harish KM
Kilo Patron
Kilo Patron

Hi @srinath1391 you can create a new before insert BR on approval table(sysapproval_approver) with following script:

 

script:

approveDuplicateApproval();
function approveDuplicateApproval(){
//Must have link to record being approved
if(current.document_id || current.sysapproval){
//Query for approval records for this user/record
var app = new GlideRecord('sysapproval_approver');
//Handle empty document_id and sysapproval fields
if(!current.document_id.nil()){
app.addQuery('document_id', current.document_id);
}
else if(!current.sysapproval.nil()){
app.addQuery('sysapproval', current.sysapproval);
}
app.addQuery('approver', current.approver);
app.addQuery('state', 'approved');
//Optionally restrict to current workflow
//app.addQuery('wf_activity.workflow_version', current.wf_activity.workflow_version);
app.query();
if(app.next()){
//If previous approval is found set this approval to 'approved'
current.state = 'approved'; // you can set to no longer required as well
current.comments = "Approval marked by system as 'Approved' due to a previous approval on the same record by the same user.";
}
}
}

Regards
Harish

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi @srinath1391 

Did you try flow designer for this.
Flow designer is OOTB managing this.

 

C

If the provided solution meets your needs, kindly consider marking it as helpful and accepting it as the solution. This helps others who may have similar questions.


Thanks and Regards,

Saurabh Gupta

Rajdeep Ganguly
Mega Guru


To avoid duplicate approvals in ServiceNow, you can follow these steps:

1. Create a script to check if the user is already in the approval list before adding them. This can be done in the Approval - User field's onChange script or in a business rule that runs before the record is inserted or updated.

2. Here is a sample script that you can use:

javascript
var approvalUser = current.approval_user;
var approvalGroup = current.approval_group;

// Check if the user is in the group
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', approvalUser);
gr.addQuery('group', approvalGroup);
gr.query();

if (gr.next()) {
// The user is in the group, so don't add them as an individual approver
current.approval_user.setDisplayValue('');
}


3. This script checks if the user is a member of the group. If they are, it clears the Approval - User field so that they are not added as an individual approver.

4. You can also use a similar script in a business rule that runs before the record is inserted or updated. This would prevent the user from being added as an individual approver if they are already in the group.

5. If you want to keep the user as an individual approver but prevent them from receiving duplicate notifications, you could modify the script to set a flag on the record indicating that the user is also in the group. Then, in your notification script, you could check this flag and skip sending the notification to the user if it is set.

6. Remember to thoroughly test any changes in a non-production environment before deploying them to production.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER