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
Tera Patron
Tera Patron

@IndianaJones 

I don't think it would be something OOB.

you will have to script it out.

Use Approval User Activity and script it like this so that it skips the current assigned to user

answer = [];

var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group.name', 'Group ABC');

// check if assigned_to user is member of that group ABC
// if yes then exclude that user

var isMember = gs.getUser().getUserByID(current.assigned_to).isMemberOf('Group ABC');

// if you want to check for assigned_to user is member of current ticket assignment group then do this

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

Hi @Ankur Bawiskar,

When I run the script using an Approval - User activity, I do not get any approvals generated. I think the issue is that the "assignment_group" might be returning null? 

 

Below is the script I am running:

answer = [];

var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group.name', 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'));
}

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