Add users to group when someone is added to On Call roster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 04:00 PM
Hi All,
I have a requirement when someone is added to a on call roster, a custom role should be added to user and if we remove user from roster the role should be removed. Can we do this by adding/removing user from group which contains the custom role. Is this possible?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 10:17 PM
Hi @pramodkumar
The stated requirement is possible to implement.
To help others quickly find solution, please mark this answer as "Helpful" or "Accept Solution" If it solved your problem/Question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 10:30 PM
Hello @pramodkumar ,
You can achieve this through Business rule.
Be sure to use the table cmn_rota_member then in your when to run use "before " . "Delete".
So that you can still access the data such as the Group and the ID of the member you are going to remove.
Then you can do advanced scripting to navigate to the Group table and find that group where your role is the remove the user.
If this has been of any help give a kudos or mark as solution, this way others with the same scenario will be able to solve their concern in no time.😀
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 10:38 PM - edited 07-14-2025 10:38 PM
Hello @pramodkumar ,
Follow below steps -
Create Business rule with below steps
Name: Add Custom Role to On-Call Member
Table: cmn_rota_member
When to run: After Insert
(function executeRule(current, previous /*null when async*/ ) {
var userId = current.member.sys_id; // Sys_id of the user being added
var roleName = 'your_custom_role'; // Name of the custom role you want to add
// Get the sys_id of the custom role
var grRole = new GlideRecord('sys_user_role');
grRole.addQuery('name', roleName);
grRole.query();
if (grRole.next()) {
var roleSysId = grRole.sys_id;
// Check if the user already has the role to prevent duplicates
var grUserRole = new GlideRecord('sys_user_has_role');
grUserRole.addQuery('user', userId);
grUserRole.addQuery('role', roleSysId);
grUserRole.query();
if (!grUserRole.next()) {
// Add the role to the user
var grNewUserRole = new GlideRecord('sys_user_has_role');
grNewUserRole.initialize();
grNewUserRole.user = userId;
grNewUserRole.role = roleSysId;
grNewUserRole.insert();
gs.info('Added role ' + roleName + ' to user ' + current.member.name + ' due to on-call roster addition.');
} else {
gs.info('User ' + current.member.name + ' already has role ' + roleName + '.');
}
} else {
gs.error('Custom role "' + roleName + '" not found. Please verify role name.');
}
})(current, previous);
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 09:45 PM
Hello @pramodkumar ,
If my answer is helpful, please accept it to close this thread for future reference.
Thank you.