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

Allen Andreas
Administrator
Administrator

Hi,

I believe you'd want to use:

if (current.getTableName() == 'change_request') {
//do x
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen..I would try with the same script in my business rule condition but can you please suggest if the script mentioned in the link is correct or not? First I tried with the same script as mentioned in link but it didn't work.

Hi Allen,

 

Tried this but no luck.

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.";
}
}
}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So can you share what did you configure and what didn't work

Did you debug it from your side?

Regards
Ankur

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