Not able to delete empty role references from sys_user_has_role table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2024 05:27 AM
In the sys_user_has_role table (User Roles) which contain rows of empty role references while we neither have (empty) role in sys_user_role table nor within any assignment group. So as per the analysis if we want to delete the empty role references from sys_user_has_role if it is not needed but looks like there is some OOTB restrictions to delete those empty references. Please suggest in this case how we can do this clean up for empty role references from sys_user_has_role table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2024 03:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2024 03:33 AM
Hi @Parveen28 ,
The inherited roles cannot be deleted directly. Event elevating the role, importing the XML after changing the inherited to false will also fail.
You have to first make inherited to inactive, then you call delete it.
var grRole = new GlideRecord("sys_user_has_role");
grRole.addEncodedQuery("Your encoded query"); //Replace with the query filter from list view
grRole.query();
while(grRole.next()){
grRole.inherited = false;
grRole.update();
grRole.deleteRecord();
}
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.