Delete orphan records from sys_user_has_role table

tiagomacul
Giga Sage

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(","));
}

 

Deleting roles creates empty roles in User's profile (visible after Express to Enterprise conversion...

Some users are having roles that they are not supposed to have

 

I couldn't find plugin and the script didn't delete records.

 

 

 

 

 

 

5 REPLIES 5

Rahul Kumar17
Tera Guru

hi

ur code is working i checked ur code.

find_real_file.png

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar