- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 07:25 AM
Is it possible dynamically to add or remove members based on the Role from the Groups.
For Example: I have created a group called Test and added a role "it_demand_manager" to the group. when a new user is created and added a role "it_demand_manager" to that user. Then that user is automatically should be added to the "test" Group.is it possible for that type of configuration or if u have any reference documents.please share this now.
Thanks in Advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 07:53 AM
@sharukh Create following business rule on sys_user_has_role table.
Replace role with your custom role it_demand_manager in filter conditions
Replace sys_id of the role mentioned on line number 5 with your own role.
Here is the script for the business rule.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var groupRole = new GlideRecord('sys_group_has_role');
groupRole.addQuery('role','2831a114c611228501d4ea6c309d626d');//Replace with sys_id of your role
groupRole.query();
if(groupRole.next()){
var groupMember = new GlideRecord('sys_user_grmember');
groupMember.initialize();
groupMember.setValue('group',groupRole.getValue('group'));
groupMember.setValue('user',current.user);
groupMember.insert();
}
})(current, previous);
Hope this helps,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 07:53 AM
@sharukh Create following business rule on sys_user_has_role table.
Replace role with your custom role it_demand_manager in filter conditions
Replace sys_id of the role mentioned on line number 5 with your own role.
Here is the script for the business rule.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var groupRole = new GlideRecord('sys_group_has_role');
groupRole.addQuery('role','2831a114c611228501d4ea6c309d626d');//Replace with sys_id of your role
groupRole.query();
if(groupRole.next()){
var groupMember = new GlideRecord('sys_user_grmember');
groupMember.initialize();
groupMember.setValue('group',groupRole.getValue('group'));
groupMember.setValue('user',current.user);
groupMember.insert();
}
})(current, previous);
Hope this helps,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 09:57 AM
Thank you so much @Sandeep Rajput .It was helpful