Empty users in user roles?

Vasu1
Mega Contributor

Hello,

Help needed,

i want to remove empty user in sys_user_has_role.list?

we found (25) empty user and not able to remove or delete is there any alternate to remove them?

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Srinivas,

 

You will not be able to delete the ones that have inherited value as True.

You can try using below background script.

var usrole=new GlideRecord('sys_user_has_role');
usrole.addEncodedQuery('pasteEncodedQueryHere');
usrole.query();
while(usrole.next())
{
usrole.inherited.setValue(false); //sets inherited value to false
usrole.update();
}

//Then deletes it
var usroleis=new GlideRecord('sys_user_has_role');
usroleis.addEncodedQuery('pasteEncodedQueryHere');
usroleis.query();
usroleis.deleteMultiple();

You can copy your EncodedQuery as below from User Role table.

find_real_file.png

Apply necessar filter to get the records that are Empty & the paste it in the script against pasteEncodedQuery within quotes.

 

View solution in original post

4 REPLIES 4

RAHUL Khanna1
Mega Guru

try to delete it from background scripts

Jaspal Singh
Mega Patron
Mega Patron

Hi Srinivas,

 

You will not be able to delete the ones that have inherited value as True.

You can try using below background script.

var usrole=new GlideRecord('sys_user_has_role');
usrole.addEncodedQuery('pasteEncodedQueryHere');
usrole.query();
while(usrole.next())
{
usrole.inherited.setValue(false); //sets inherited value to false
usrole.update();
}

//Then deletes it
var usroleis=new GlideRecord('sys_user_has_role');
usroleis.addEncodedQuery('pasteEncodedQueryHere');
usroleis.query();
usroleis.deleteMultiple();

You can copy your EncodedQuery as below from User Role table.

find_real_file.png

Apply necessar filter to get the records that are Empty & the paste it in the script against pasteEncodedQuery within quotes.

 

Hello jaspal,

Thank you the prompt response,

yes as per the instructions i tried the code it worked and deleted the empty records as expected. 

 

Thanks,

Srinivas

MarkWe
Tera Guru

Just in case someone else is having the same issue and doesn't feel comfortable using a background script:

 

In my instance the roles were inherited from some "empty" group-memberships. 

So what I did was the following:

- Remove 'empty' group-memberships from the sys_user_grpmember.list

- Remove 'empty' roles that had inherited=false from the sys_user_has_role.list

After doing this, all the empty 'roles' with inherited=true were gone.

 

In my case these were created as a result of some group memberships being inadvertently put in an update set that was taken from one instance to another.