- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 12:01 AM
Hi Team,
We have a role called "Internal Role" assigned to users, and some groups have the "External Role" assigned.
For example, if I need to add a user to any group that has the "External Role," the "Internal Role" must be removed from the user’s account.
I need to achieve this functionality via a business rule. Could you please help me with this requirement?
Thank you in advance.
Best regards,
Siva
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:46 AM
your BR should be before insert on sys_user_grmember
Condition as: Group == Group Name
function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var usr = current.getValue('user');
var role = 'sn_customerservice.customer';
var usrrole = new GlideRecord('sys_user_has_role');
usrrole.addQuery('user', usr);
usrrole.addQuery('role.name', role);
usrrole.query();
if (usrrole.next()) {
usrrole.deleteRecord();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 01:17 AM
usually we should assign users to groups and groups should have role.
If you add user to group 2(give external role) you can remove that user from group 1(give internal role)
BR: After insert on sys_user_grmember
What script did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:25 AM
Hi @Ankur Bawiskar,
Thank you for your response. The "Internal Role" was assigned by default to every user in the user table. If I need to add a user to a group with the "External Role," the user cannot be added due to the restrictions imposed by the "Internal Role" in the user table. Therefore, in order to add a user to any group with the "External Role," the "Internal Role" must first be removed from the user’s account.
I tried Before BR, But no luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:46 AM
your BR should be before insert on sys_user_grmember
Condition as: Group == Group Name
function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var usr = current.getValue('user');
var role = 'sn_customerservice.customer';
var usrrole = new GlideRecord('sys_user_has_role');
usrrole.addQuery('user', usr);
usrrole.addQuery('role.name', role);
usrrole.query();
if (usrrole.next()) {
usrrole.deleteRecord();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader