Keeping Assigned To from approving their own change

gwow
Kilo Contributor

I'm looking for ideas on keeping the assigned to from approving their own changes. Whenever a change is created, the approval group is the ("approver: " + assigned group) that is tasked for that particular change. If the assigned to is a member of both the assignment group and approval group, they will have the ability to approve their own change. I would like to be able to limit or not allow the assigned to the ability to approve their own change. Any ideas on how to go about and completing this task?

11 REPLIES 11

marcguy
ServiceNow Employee
ServiceNow Employee

something along these lines but changing the field names to the ones you need:

var user = gs.getUserID();
var myUserObject = gs.getUser();
var owner = current.parent.u_change_owner;
var requestor = current.parent.u_requested_by;
//gs.log(user + owner + requestor);
if (user == owner){
gs.addInfoMessage('You are the owner of the change, therefore not authorised to approve');
current.setAbortAction(true);
}
else if (user == requestor){
gs.addInfoMessage('You are the requestor of the change, therefore not authorised to approve');
current.setAbortAction(true);
}


gwow
Kilo Contributor

I actually need to be able to delete the user from the list of approval users on the approvers tab. I believe your code only inspects the change itself not the approvals.


I am looking to do the same. Did you find a resolution for this please?


gwow
Kilo Contributor

just created this bus rule and it appears to work. I'm still testing it out.

var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval',current.sys_id);
gr.addQuery('approver',current.assigned_to);
gr.query();
while(gr.next()){

gr.deleteRecord();
}