- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2020 01:33 PM
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?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2020 09:49 AM
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.
Apply necessar filter to get the records that are Empty & the paste it in the script against pasteEncodedQuery within quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2020 09:39 AM
try to delete it from background scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2020 09:49 AM
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.
Apply necessar filter to get the records that are Empty & the paste it in the script against pasteEncodedQuery within quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2020 10:14 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 09:25 AM
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.