Same user cannot approve change request again in 2nd level approver

Harsha Pandey
Tera Expert

Hi,

Customer requirement is that same user should not be able to approve change request again or I can say in 2nd level approval.

I had gone through community and found out post https://servicenowguru.com/scripting/business-rules-scripting/prevent-redundant-approval-requests-servicenow/

I tried this with one more condition as current.getTableName('change_request') as I need it to to run for change_request but did not work.

Please help me out!!

1 ACCEPTED SOLUTION

Hi,

your requirement is to make it work only for change_request table and hence it would only run for those approvals

Won't impact any other table

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

15 REPLIES 15

Hi Ankur, I applied gs.log and tried to run in background script but it is saying cannot read "document_id" from null. Can you please help me how to apply logs correctly and check. Please find attachment of the actual script.

Hi,

share the scripts here and not screenshots

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Please find below script :

Table:sysapproval_approver

When:before , insert/update

Order:300

Condition:current.state.changesTo('requested')&&(current.getTableName()=='change_request')

Script:

//Check to see if user has previously approved
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 = 'not_required';
current.comments = "Approval marked by system as 'Not Longer Required' due to a previous approval on the same record by the same user.";
}
}
}

Hi,

BR condition should be this

Condition:current.state.changesTo('requested')&&(current.source_table =='change_request')

keep script as it is

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

It worked!!! You are amazing...but I need to know if this would impact the existing workflow of changes? Will there be any other impact because of this script?