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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should be knowing which members to exclude from that group

1) form an array of those users sys_id and use that in query as below

answer = [];

var groupSysId = '';

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

groupSysId = gr.sys_id;

}

var sysIdArray = ['sys_id1', 'sys_id2', 'sys_id3']; // give here the 3 user's sys_ids

var member = new GlideRecord('sys_user_grmember');

member.addQuery("group", groupSysId);

member.addQuery("user.sys_id", "NOT IN", sysIdArray);

member.query();

while(member.next()){

answer.push(member.getValue("user"));

}

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

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