How to remove role for user in background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 09:08 PM
Hi,
I have two roles snc_internal and snc_external.
Ex:
user - Test(Internal user)
Test user has snc_internal and snc_external roles.
Now I want to remove snc_external role for Internal users(Test user).
I have around 1000 users with same case.
How can I remove snc_external for Internal user

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 09:20 PM
Hi,
You can write a fix script and glide to sys_use_has_role table.
Get records role = snc_external and delete records.
Please check below link for script:
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2021 09:22 PM
var userRole = new GlideRecord('sys_user_has_role');
userRole.addEncodedQuery('role.name=snc_internal^ORrole.name=snc_external');
userRole.query();
userRole.deleteMultiple();
Execute the script in background script
Warning : Whoever has snc internal or external roles, they will lose them. This will happen to all users. Add another query to ensure snc internal and external is not removed to key users