Prevent assignment group manager approving change request when state is assess

Shane_Waka
Tera Contributor

Hi There,

 

This is my first ever post to the community. I am relatively new to being a ServiceNow administrator. I would like some help implementing this requirement "Prevent assignment group manager approving change request when state is assess" This is my code below, also I can't actually tell if it is runs.

 

(function executeRule(current, previous /*null when async*/ ) {

    var groupApproval = GlideRecord('sysapproval_group');
    groupApproval.get(current.group);
   
    var gr = GlideRecord('change_request');
    gr.get(current.sysapproval);
   
    var man = GlideRecord('change_request');
    man.get(current.sysapproval.assignment_group.manager.sys_id);

    if (groupApproval.assignment_group == gr.assignment_group) {
        if (man == current.approver.sys_id) {
            current.state = 'not_required';
            return;
        } else
            return;
    } else
        return;



})(current, previous);
 
Any help would be appreciated
2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Shane_Waka You can create a business rule like to following and cancel the approval.

 

Screenshot 2024-08-11 at 11.09.15 AM.pngScreenshot 2024-08-11 at 11.09.25 AM.png

 

Here is the script.

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	//Check if the approver is the manager of change request assignment group and change request is in Assess state

	if(current.parent.state=='-4'&&gs.getUserID()==current.parent.assignment_group.manager){
		gs.addInfoMessage('Assignment Group Manager can not approve the change request if it is in Assess state');
		current.setAbortAction(true);
	}

})(current, previous);

Hi Sandeep Rajput Thank you for providing this, I will see how this works in our Dev environment. I will get back to you with my results.

Thanks a again much appreciated