Exclude user from group approval

IndianaJones
Tera Expert

I am trying to create a way for an incident to be reviewed by a peer on the team before it can be resolved. I went with the out of the box group approval, but the issue is that the person requesting the approval (the person assigned to work the ticket) is also part of the group that has to approve the request. So then they get a approval request for their own approval, which makes them able to approve their own approval request. I'd assume ServiceNow had an easy way to not include the person in the group approval if they were part of the team. Anyone know of a quick way to do this?

1 ACCEPTED SOLUTION

Hi Rocky,

please check updated script

you were querying with group.name but giving sys_id so updated code below

answer = [];

var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.assignment_group);

var isMember = gs.getUser().getUserByID(current.assigned_to).isMemberOf(current.assignment_group);

if(isMember == true){
gr.addQuery('user','!=',current.assigned_to);
}

gr.query();
while(gr.next()){
answer.push(gr.getValue('user'));
}

Regards
Ankur

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

View solution in original post

13 REPLIES 13

@Ankur Bawiskar  That did it! Thank you so much for the help. Looks like I need to research more about scripting to understand the differences on group and group.name. 

 

 

Hi,

You are welcome.

Just for information.

group -> would check against sys_id

group.name -> would check against name

if you query for group.name then you need to give current.assignment_group.name

if you query for group then you need to give sys_id

Regards
Ankur

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

Hi Ankur,

I have used your script in one of my group approvals, But still the approval is triggering to that user.Please find the below script.

// Set the variable 'answer' to a comma-separated list of group ids or an array of group ids to add as approvers.
answer = [];

var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group','2afc7336db6e805049df7ffb8c961978');

var isMember = gs.getUser().getUserByID(current.request).isMemberOf('2afc7336db6e805049df7ffb8c961978');

if(isMember == true){
gr.addQuery('user','!=',current.request);
}

gr.query();
while(gr.next()){
answer.push(gr.getValue('user'));
}
// For example:
//       var answer = [];
//       answer.push('id1');
//       answer.push('id2');

 find_real_file.png

Hi,

I assume this workflow is on incident table so current object means incident record.

Also I assume you want to check for the current assigned to user

So please update as below

// Set the variable 'answer' to a comma-separated list of group ids or an array of group ids to add as approvers.
answer = [];

var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group','2afc7336db6e805049df7ffb8c961978');

var isMember = gs.getUser().getUserByID(current.assigned_to).isMemberOf('2afc7336db6e805049df7ffb8c961978');

if(isMember == true){
gr.addQuery('user','!=',current.assigned_to);
}

gr.query();
while(gr.next()){
answer.push(gr.getValue('user'));
}
// For example:
//       var answer = [];
//       answer.push('id1');
//       answer.push('id2');

Regards
Ankur

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

No Ankur,

 

This workflow is in SC_REQ_ITEM table.

Actually my scenario is, in my catalog item i have a variable called req_for. and i have an approval group in the catalog item. If suppose i select requested_for user any member in that group. Approvals should trigger all members expect the select req_for user