- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks 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 ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
even from the data management it is not getting deleted, so I have raised a HI case and they have provided me this article
Role Management Inheritance Issues - Support and Troubleshooting
and suggested this as next steps
Next Steps:
We need to run a script to remove the discrepancies for inherited roles.
Please note that this is a standard change and doesn't cause any harm to anything. This will only fix the records in 'sys_user_has_role' table.
So kindly provide your consent and a suitable time window to implement this CHG directly on your prod instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
tried both Ankur, but didn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
without you sharing the script and debugging results we can't help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am saying that I have tried the options and script you have mentioned. Those options didn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
even from UI Data Management it didn't delete?
so if you have debugged anything share the outcomes
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
