Prevent L2 approver from approving if they are the requestor but allow to approve as L3

Ramel
Mega Guru

Hi Community,

 

In the change approval process, approvers are groups and they are based on the CI and Business/Technical Service. There is a scenario when the user could be a member of multiple groups, (L1, L2, L3) so the same approver could show up as the approver more than once. We are trying to prevent the same approver if they are the change requestor (requested_by) from being able to approve as L2 however if they are found in L3 group they should be able to approve. In our case the L1 approver is used as technical assessment so if you are the requestor, you still can approve as L1 but should not allow as L2 approver. I am currently doing it by Business Rule but I have no success implementing it. Open for any suggestions.

 

Note: Our business service field in the CHG form which we use to get the L1 and L2 approvers are fields in the cmdb_ci_service_technical table where we have defined L1 approvers and L2 approvers.

 

Below is my business rule:

approve();

function approve(){
 
        if(current.approver == current.document_id.requested_by){
        var app = new GlideRecord('sysapproval_approver');
        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');
        app.query();
        if(app.next()){
            current.state = 'not_required';
            current.comments = "Approval marked by system as 'No Longer Required' as approver is the same as Requested By or Opened By.";
            //gs.addInfoMessage('L1 Approval cannot be the same as  "Requested By" or "Opened By" of the RFC.');
        }
    }
}

 

This works and can approve as L1, L2 is then marked as No Longer Required, however as L3 if the user (requestor) is found in the approver list, it should allow them to approve but currently the script is also marking them as no longer required.

 

Alternatively, another approach to solve my requirement, in the workflow, we have defined there the L2 group approval activity. I am thinking how can I script in the workflow that if the requestor/opened_by is also a member of the approval group, it will not be added as approver. Appreciate your response.

 

Regards,

Ramel

1 ACCEPTED SOLUTION

Ramel
Mega Guru

Found a solution to do it within the workflow. When checking for the L2 approver, I just changed the existing group approval to user approval and query sys_user_grmember based on the approver group before pushing it as approver removing requested_by/opened_by

View solution in original post

1 REPLY 1

Ramel
Mega Guru

Found a solution to do it within the workflow. When checking for the L2 approver, I just changed the existing group approval to user approval and query sys_user_grmember based on the approver group before pushing it as approver removing requested_by/opened_by