The CreatorCon Call for Content is officially open! Get started here.

Delete orphan records from sys_user_has_role table

gee
Tera Guru

Hi Team,

I have an issue with deleting orphan records from sys_user_has_role table.

Tried with fix script to delete these records using GlideRecord, failed.

Delete button is disabled, even though schema level deletion is enable.

Also dried to deleted the user and imported the same user record using XML (user record export). Still role definitions are there!

Is there any method to delete these records from the above table?

Any suggestion please?

Platform is on Helsinki Patch 8.

Thanks & Regards,

Gee Abraham

1 ACCEPTED SOLUTION

gee
Tera Guru

Hi All,


This issue has been resolved by installing the following plugin.


Contextual Security: Role Management Enhancements (com.glide.role_management.inh_count)



Many thanks for your efforts to resolve this issue.



Best Regards,


Gee


View solution in original post

29 REPLIES 29

gee
Tera Guru

sys_user_has_role Table.GIF


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Please share your script.


gee
Tera Guru

Hi Pradeep,


Here is the script that I have executed. Thanks, Gee.


----


var usr = new GlideAggregate("sys_user_has_role");


usr.addQuery("user", "7225d7164f03a2007b3be6518110c792");


usr.query();


while(usr.next())


  {


  usr.deleteRecord();


  usr.update();


  gs.log('********* sys_user_has_role ' + usr.role.name + ' ' + usr.granted_by);


  }


----


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Gee,



Replace


usr.deleteRecord();


  usr.update(); with



usr.setWorkflow(false);


usr.deleteMultiple();



P.S : Try this on dev instance first