- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2020 02:38 PM
Hello,
How to add new users to in a particular group, when a table is updated with new user.
ex: table : custome table
Group : Service Incident Group
I know for this i have to write business rule, here i'm looking for script.
Thanks and Regards,
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2020 02:47 PM
write an 'after' 'insert' and 'update' business rule in the custom table-
var gr=new GlideRecord('sys_user_grmember');
gr.initialize();
gr.group="Sys_ID of Service Incident Group";// best practice is to get the sysID using a property
gr.user=current.FIELD_NAME_WHICH_CONTAINS_THE_NEW_USER_IN_CUSTOM_TABLE;
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2020 02:47 PM
write an 'after' 'insert' and 'update' business rule in the custom table-
var gr=new GlideRecord('sys_user_grmember');
gr.initialize();
gr.group="Sys_ID of Service Incident Group";// best practice is to get the sysID using a property
gr.user=current.FIELD_NAME_WHICH_CONTAINS_THE_NEW_USER_IN_CUSTOM_TABLE;
gr.insert();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 10:59 AM
Thank you, your script helped me.
I also used the below to remove the user from the group when the condition reverses.
(function executeRule(current, previous /*null when async*/) {
var user = current.sys_id; //Field name which contains the new user in custom table. I'm using sys_user table so it's just sys_id.
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',user);
gr.query();
while (gr.next()) {
gr.deleteRecord();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 06:36 PM
Great !
You can also start using GlideQuery instead of GlideRecord-
var query = new global.GlideQuery('sys_user_grmember')
.where('user', current.sys_id)
.deleteMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2021 06:43 PM
A little warning - that GlideRecord and GlideQuery will remove the User from ALL Groups. You need to add a condition to include the Group in the search as well.