- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 12:22 PM
I have seen several threads on this subject, but none of the solutions proposed seem to work for me, so I thought I would put this out there. I have 2 business rules to add users to a group based on criteria changing in the Sys_User table. the first rule, which is to add a user to the group is working perfectly. It is set to run after and when the Supervisor Flag (user defined field) changes to true on insert or update.
var gr = new GlideRecord('sys_user_grmember');
gr.initiate();
gr.user = current.sys_id;
gr.group = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//sys_id of the group to be added to
gr.insert();
the 2nd rule is the remove from group when the supervisor flag changes to false on update.
var gt = new GlideRecord('sys_user_grmember');
gt.initiate();
gt.user = current.sys_id;
gt.group = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//sys_id of the group to be removed from
gt.deleteRecord();
I am probably oversimplifying by simply reversing the add rule and using delete record instead of insert. Any thoughts on what I can try to make this work?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 12:47 PM
** Copying Jaspal's code here with some fixes
var gt = new GlideRecord('sys_user_grmember');
gt.addQuery('user',current.sys_id);
gt.addQuery('group','sys_id_if_group');
gt.query();
while(gt.next())
{
gt.deleteRecord();
}
Let me know if that works
Cheers,
Dylan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 12:32 PM
to delete can you try with script below.
var abc = new GlideRecord("sys_user_grmember");
abc.addQuery('user', current.sys_id);
abc.query();
while (abc.next())
abc.deleteRecord();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 12:37 PM
Hi Keith,
Try using below snippet
var gt = new GlideRecord('sys_user_grmember');
gt.addQuery('user',current.sys_id);
gr.addQuery('group','sys_id_if_group');
while(gt.next())
{
gt.delete();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 12:47 PM
** Copying Jaspal's code here with some fixes
var gt = new GlideRecord('sys_user_grmember');
gt.addQuery('user',current.sys_id);
gt.addQuery('group','sys_id_if_group');
gt.query();
while(gt.next())
{
gt.deleteRecord();
}
Let me know if that works
Cheers,
Dylan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 01:04 PM
Dylan and Jaspal,
That works perfectly. thanks for your help!
Keith