Not able to delete empty role references from sys_user_has_role table

Parveen28
Tera Contributor

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.

6 REPLIES 6

Hi @Sumanth16 

 

I'll test on this. 

Thank you for your response.

 

Thx

SN_Learn
Kilo Patron
Kilo Patron

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.