Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Avoiding asking for approval from the same person if they have already approved

New user1212
Tera Contributor

Hi.
I am looking for a way to avoid repeating requests for approval several times to one person if, for example,  is a member of several groups or is designated in several places. I saw that there was a post from Guru that many recommended, but now the page is empty and I don't really know how to approach it.
I will be grateful for help!

1 REPLY 1

Harish KM
Kilo Patron
Kilo Patron

Hi @New user1212 you can create a before insert/update BR on approval table with below code:

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');
app.query();
if(app.next()){
//If previous approval is found set this approval to 'approved'
current.state = 'approved';
current.comments = "Approval marked by system as 'Approved' due to a previous approval on the same record by the same user.";
}
}
}

Reference : https://servicenowguru.com/business-rules-scripting_prevent-redundant-approval-requests-servicenow/

Regards
Harish