Delete orphan records from sys_user_has_role table

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2018 11:46 AM
Hi Team,
Platform is Jacarta
I have an issue with deleting orphan records from sys_user_has_role table.
Gee, answered, install plugin
Contextual Security: Role Management Enhancements (com.glide.role_management.inh_count)
https://community.servicenow.com/community?id=community_question&sys_id=c164c769dbd8dbc01dcaf3231f9619e8
workarround
deleteEmptyRoles();
function deleteEmptyRoles() {
//script to delete the empty roles a user contains
var roleL = [];
var gr = new GlideRecord("sys_user_has_role");
gr.addNullQuery('role.sys_id');
gr.query();
gs.print("Number of records that will be deleted: " + gr.getRowCount());
while (gr.next()) {
roleL.push(gr.getValue('sys_id'));
//gr.deleteRecord();
}
gs.print("the sys_ids of the records that will be deleted are: ");
gs.print(roleL.join(","));
}
Some users are having roles that they are not supposed to have
I couldn't find plugin and the script didn't delete records.
- 2,439 Views
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2019 02:37 AM