User roles inherited but not from group and roles are not manually added. unable to delete them
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi
I found an inactive user with roles but not added in any group or not manually added. all the roles say inherited true. Unable to delete them from sys user has role table and background script also didn't work.
how to deleted these roles ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi @RahulRAJAS
Use script as shared
https://www.servicenow.com/community/developer-forum/removing-roles-of-inactive-users/m-p/1365936
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
didn't work Atul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi @RahulRAJAS
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
No scripting required
-> navigate to sys_user_has_role table
-> search for your inactive user
-> the Right Click Data Management -> Delete All with preview
this script in global scope in background script will work fine
(function() {
var userId = 'sys_id_of_the_user'; // Replace with actual sys_id
var roleGR = new GlideRecord('sys_user_has_role');
roleGR.addQuery('user', userId);
roleGR.query();
while (roleGR.next()) {
// Only process if the role is inherited
if (roleGR.inherited == 'true') {
roleGR.deleteRecord();
}
}
})();
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader