Preventing a Requester from Approving Their Own Form

ljschwaberow
Giga Expert

Scripting is still a very new to me.... that being said does anyone have scripting (or a different way) to prevent the requester of a change request form from being included in the list of approvers. On occasion the requester of a change request is also in the approving group and we don't want their name to come up in the list in the this case.

1 ACCEPTED SOLUTION

In the activity properties you will need to remove the "IT Infrastructure Managers" group from the groups field and instead script the members.   You click on the "Advanced" field and then a script section will show up.   The following script will add anyone within this group to the approvers list unless they are the requested_by user.



answer = [];


var approvers = new GlideRecord('sys_user_grmember');


approvers.addQuery('group.name', 'IT Infrastructure Managers');


approvers.query();


while(approvers.next()) {


    if(approvers.user.toString() != current.requested_by.toString()) {


          answer.push(approvers.user.toString());


    }


}


View solution in original post

6 REPLIES 6

adiddigi
Tera Guru

I'm guessing you are using Workflow approval-user activity:



The code will be something like this:



//get all the approvals from a Glide



while(gr.next() && gr.sys_id != current.requested_by)){


answer.push(gr.sys_id)


}


Also, do let me know what you are using in your workflow.


Yes, that is correct I am using workflow approval - user activity. Here is an image of one of the Approval - User Activities from one of the workflow.


find_real_file.png


In this case what I'd do is add an IF workflow activity just before your approval activity. Then build a little script (like shown before) to check if they are the same person. If they are, simply go to the next step in the workflow. If they are different, lead into the approval activity you're showing above.


In the activity properties you will need to remove the "IT Infrastructure Managers" group from the groups field and instead script the members.   You click on the "Advanced" field and then a script section will show up.   The following script will add anyone within this group to the approvers list unless they are the requested_by user.



answer = [];


var approvers = new GlideRecord('sys_user_grmember');


approvers.addQuery('group.name', 'IT Infrastructure Managers');


approvers.query();


while(approvers.next()) {


    if(approvers.user.toString() != current.requested_by.toString()) {


          answer.push(approvers.user.toString());


    }


}