- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 07:39 AM
I have a checkbox on the user table to indicate whether or not a user is a manager. I would like a business rule to maintain a group for managers by adding and deleting users from the group based on wether or not this box is checked.
The add script seems to be working correctly. But the delete script is deleting users from any group they are a member of. Here is the faulty script:
var gt = new GlideRecord('sys_user_grmember');
gt.addQuery('user',current.sys_id);
gt.addQuery('656d28f81386570031f25e7f3244b0be','sys_id_if_group');
gt.query();
while(gt.next())
{
gt.deleteRecord();
}
Help me to understand what I am doing wrong!
Thank you so much!
Daniel
Solved! Go to Solution.
- Labels:
-
Operational Intelligence

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 11:31 AM
Daniel,
Try with the below-edited one and let me know if it worked.
if(current.checkbox_name == true)
{
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group','sysid_of_managers_group');
grp.addQuery('user',current.sys_id);
grp.query();
if(!grp.next())
{
grp.initialize();
grp.group = sysid_of_managers_group;
grp.user = current.sys_id;
grp.insert();
}}
else
{
var grp1 = new GlideRecord('sys_user_grmember');
grp1.addQuery('group','sysid_of_managers_group');
grp1.addQuery('user',current.sys_id);
grp1.query();
if(grp1.next())
{
grp1.deleteRecord();
}
}
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2019 03:17 PM
Hi Archana,
Any idea why this wouldn't work the same way on the HR profile instead of sys_user? Adding the user to the group works, but the deletion doesn't.
if(current.u_organisation == 'Payroll'){
var grpPay = gs.getProperty("sn_hr_core.payroll.group");
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', current.user.sys_id);
gr.addQuery('group', 'grpPay');
gr.query();
if(!gr.next()){
gr.initialize();
gr.group = grpPay;
gr.user = current.user.sys_id;
gr.insert();
}
} else {
var gr1 = new GlideRecord('sys_user_grmember');
gr1.addQuery('user', current.user.sys_id);
gr1.addQuery('group', 'grpPay');
gr1.query();
if(gr1.next()){
gr1.deleteRecord();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 06:26 AM
Hi,
I believe that you're doing something wrong here in the below line.
.addQuery('group', 'grpPay');
Try removing grpPay from quotations.
Thanks,
Archana

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 12:15 PM
Thanks Archana, I figured it out.
I needed to write the Business Rule in the Global Application scope, instead of HR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2018 02:29 PM
Thank you so much for your help! Got it working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2018 09:11 PM