Roles Not Removing from User

yana7
Tera Contributor

I'm trying to remove roles from a user, but they're not being removed.

  1. [Image 1] This is the user I want to remove roles from.

    yana7_3-1719547173800.png

     

  2. [Image 2] I've removed the roles in the Edit Role section and saved.

    yana7_4-1719547191895.png

     

  3. [Image 3] The roles are still listed in the Related list tab.

    yana7_5-1719547211477.png

     

When I check the User tab from the Role itself, the user account is still there.

yana7_6-1719547231708.png

yana7_8-1719547295090.png

What should I do  to Remove Roles?

1 ACCEPTED SOLUTION

Hi @yana7 ,

 

Please try the below in background script:

var userRole = new GlideRecord('sys_user_has_role');
userRole.get('61737f1bc36602103869d64d050131ee'); //Replace SysId of the role relationship in the [sys_user_has_role] table
userRole.inherited = false; //Updating it to false, then only we will be able to delete it.
userRole.update();
userRole.deleteRecord();

 

Highlighted sys_id is what you need to replace in the above code as per your requirement

SN_Learn_0-1719815887609.png

 

Note: Please try in non prod first and check and it is not recommended to run background script in Prod.

 

 

Mark this as Helpful / Accept the Solution if this helps

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

13 REPLIES 13

SN_Learn
Kilo Patron
Kilo Patron

Hi @yana7 ,

 

These are inherited roles that is the reason why it is not showing in the slush bucket. Removing the group from user will remove the inherited role.

 

If you want to remove a particular set of roles, then follow the steps mentioned in the post:

Unable to remove roles from Users who have inherited them. 

 

Please mark the answer as correct/helpful based on impact.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

yana7
Tera Contributor

I'm getting a 'Permission Denied' error. I'm using the Security Admin role and I've been given permission to delete from that table.

yana7_0-1719568955037.png

 

Sid_Takali
Kilo Patron
Kilo Patron

HI @yana7 You might need to remove them from group first before trying to remove roles. 

yana7
Tera Contributor

I've removed him from the group