how to exclude 2 members from group approval

kamer
Kilo Expert

How to exclude only three users from group approval in workflow. I am using Approval user activity.

Here is my script which is going for group.

var gr = new GlideRecord("sys_user_group");
gr.addQuery("parent", current.u_designated_cab);
gr.addQuery("type","CONTAINS",'6aa67778dbf40700e907572e5e9619cd');
gr.query();
if (gr.next()) {

answer = gr.sys_id.toString();
}

 

let me now how to filter out members from this group

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If your script is the best way to get to the group in question, that's fine for starters, then you would run this script inside the if block instead of your answer line.  Otherwise, just use this script with a hard-coded group sys_id if it will always be the same

answer = [];
var mbr= new GlideRecord('sys_user_grmember');
mbr.addQuery('group', gr.sys_id.toString()); //or use following line instead
//mbr.addQuery('group', '1'); //replace 1 with sys_id of group
mbr.addQuery('user','NOT IN','1, 2, 3'); //replace 1, 2, 3 with sys_ids of users to exclude
mbr.query();
while(mbr.next()){
answer.push(mbr.user.toString());
}

 

View solution in original post

5 REPLIES 5

Saurabh singh4
Kilo Guru

Hi Kamer

You can check this example,This will give some clarity how to remove a member from the group

https://community.servicenow.com/community?id=community_question&sys_id=04e7072ddb1cdbc01dcaf3231f96...

Please mark my answer correct and helpful ,if this helps you in any way

Thanks in advance

Saurabh 

 

Pranav Bhagat
Kilo Sage
var gr= new GlideRecord('sys_user_grmember');

gr.addQuery('group',current.assignment_group);

gr.addQuery('user','!=',current.assignment_group.manager);

gr.query();

while(gr.next()){

answer.push(gr.getValue('user'));

}

 

try something like  this.

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Pranav

 

Brad Bowman
Kilo Patron
Kilo Patron

If your script is the best way to get to the group in question, that's fine for starters, then you would run this script inside the if block instead of your answer line.  Otherwise, just use this script with a hard-coded group sys_id if it will always be the same

answer = [];
var mbr= new GlideRecord('sys_user_grmember');
mbr.addQuery('group', gr.sys_id.toString()); //or use following line instead
//mbr.addQuery('group', '1'); //replace 1 with sys_id of group
mbr.addQuery('user','NOT IN','1, 2, 3'); //replace 1, 2, 3 with sys_ids of users to exclude
mbr.query();
while(mbr.next()){
answer.push(mbr.user.toString());
}

 

Hi Brad,

Thank You it works:)