How to set approval state to No Longer Required if a group member meets certain conditions?

thrsdy1512
Tera Expert

If a record on the change task table is assigned to a user who is also a member of an approval group that is linked to the change request, I want the approval state for that Change request to be 'No Longer Required' for that specific user only. 

I have created a business rule on the approvals table which runs on insert however I can't get it to work. 

 

new change is logged > a change task (type = peer review) is created as part of it > the change task is assigned to user #1 > the change progresses and triggers approval > in scenarios where user #1 is also member of the approval group the approval state for them is no longer required & work note added to say they can't approve as they are assigned to the change task> other members of the approval group still need to approve the record.

 

My script is:

(function executeRule(current, previous /*null when async*/) {
   
    var sourceTable = current.change_request;
    var sourceRecord = new GlideRecord(changeRequest);
    sourceRecord.get(current.sys_id);
   
    var changeTaskGR = new GlideRecord('change_task');
    changeTaskGR.addQuery('change_request', sourceRecord.sys_id);
    changeTaskGR.addQuery('type', 'peer review');
    changeTaskGR.query();

    while (changeTaskGR.next()) {
        var peerReviewAssignee = changeTaskGR.assigned_to;
       
        var approvalGroupGR = new GlideRecord('sys_user_grmember');
        approvalGroupGR.addQuery('group', current.group);
        approvalGroupGR.query();
       
        while (approvalGroupGR.next()) {
            if (approvalGroupGR.user == peerReviewAssignee) {
                current.state = 'no longer required';
                current.update();
            }
        }
    }
   
})(current, previous);
7 REPLIES 7

@thrsdy1512 

the BR should work fine.

What debugging have you done so far?

the choice value for No Longer Required is not_required

did you update that script and see?

Are you sure you are using correct type during comparison of change task?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@thrsdy1512 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@thrsdy1512 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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