restrict approval if, requester is approver

rajsrajpoot
Kilo Contributor

Hi,

I have a requirement to restrict the user for approving the change request where user is also requester.

Have created BR (After) on change request,

var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval', current.sys_id);  

gr.addQuery('approver', <<caller>>);  

gr.query();  

if(gr.next())  

{  

current.setAbortAction(true);  

gs.addInfoMessage('Caller approval restricted')  

}

User should be restricted with every mode, i.e. via approval form, approve/reject button, list edit under related list on change record, inbound email action. Please suggest.

2 REPLIES 2

sangareddy
ServiceNow Employee
ServiceNow Employee

Hi Raj,



As per my understanding ,once approval generated then only we can have an interaction with sysapproval_approval table.. before you add any user as approver on change record, compare the adding user to currently login user. if both users same then restrict the user addition as an approver.



i think it would be easy, instead of playing with approver after generating it.



Thanks


Trinadh


Rajesh Annepak1
Kilo Guru

Hi Raj,




You can create "If activity" in the workflow and place it before "Approval activity" with the script as. Modify it as per your req.



answer = ifScript();  


function ifScript() {  


  if ( current.requester is part of the approval group ) {  


  return 'no';  


  }  


else{  


  return 'yes';  


}  


}  



Please mark helpful / Correct if your query is resolved



Rajesh kumar Annepaka