Unable to remove Inherited roles from user

Pihu1
Tera Contributor

Hi,

 

I need help in inherited roles.How to remove inherited roles for 50 users.

 

Thanks,

Pihu

15 REPLIES 15

Pihu1
Tera Contributor

I have tried but no use.Not able to delete 

Chris35
Giga Expert

Hello,

You should be able to do this in a background script.
But since it is inherited that stops you, you have to do it in two steps with an update to the record first.

Go to table: "sys_user_has_role" (sys_user_has_role.list in the filter navigator), filter out the users this applies to.
Right click on your filter and select, "Copy query".
Go to Background Script (Application Navigator: System Definition -> Scripts - Background).

In the parenthesis after "addEncodedQuery", insert the query you copied into the table. And execute the script.
I recommend that you do this twice, where the first time is a verification that you receive the correct data.

Test run :

var gr = new GlideRecord("sys_user_has_role");
gr.addEncodedQuery("your copied query");
gr.query();

gs.print("Count : " + gr.getRowCount());
while(gr.next()){
gs.print("User : " + gr.getDisplayValue("user") + " Role : " + gr.getDisplayValue("role"));
}


Execution :

var gr = new GlideRecord("sys_user_has_role");
gr.addEncodedQuery("your copied query");
gr.query();

while(gr.next()){
gr.inherited = false;
gr.update();

gr.deleteRecord();
}

Pihu1
Tera Contributor

Thank you for the reply i will try this and l ll let you know if this works

 

 

I was missing the "inherited = false" component and could not figure out why it was working.  Appreciate the code snippet example.

Ken24
Giga Expert

As a side note, you need to Elevate Roles to do this.