Automatically remove user from group

ejaram
Kilo Expert

Hello,

I am trying to build an automated user remove catalog request in ServiceNow and am having trouble with the script part.

A user will fill out a form with:
User's name - variable = group_members
Group to be removed from - variable = workgroup

I want to user a GlideRecord to search for that user and remove him/her from the group.

I have been using the below and cannot get it to work. Any ideas?:



var rec = new GlideRecord('sys_user');
rec.addQuery('sys_id', current.variables.group_members);
rec.query();
while (rec.next())
{
var rec1 = new GlideRecord('sys_user_grmember');
rec1.addQuery('sys_id', current.variables.workgroup);
rec1.query();
while (rec1.next())
{
rec1.deleteRecord();
}
}

5 REPLIES 5

ejaram
Kilo Expert

Thank you all for the help!