- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2017 11:11 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2017 06:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2017 02:24 PM
Hi Pradeep,
Does 'deleteMultiple();' work inside the while loop?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 03:40 AM
Hi Gee,
Can you removing update() and try it. Because deleteRecord will delete the record itself, so there is no option to update it and this is just my assumption.
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 03:10 AM
Hi Pradeep,
I have tried the given commands and it did NOT worked. There may not be any workflows attached to this table's record.
Any other option please?
Thanks & Regards,
Gee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 03:11 AM
------
var usr = new GlideAggregate("sys_user_has_role");
usr.addQuery("user", "7225d7164f03a2007b3be6518110c792");
usr.query();
while(usr.next())
{
usr.setWorkflow(false);
usr.deleteMultiple();
gs.log('********* sys_user_has_role ' + usr.role.name + ' ' + usr.granted_by);
}
------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 04:29 AM
Hi Gee,
Thanks for your concern regrading this,
Please use the below script in background script to delete the records from the table:
var users = new GlideRecord('sys_user');
users.addQuery('user_name', 'bernard.laboy');
users.query();
if(users.next()){
var hasRole = new GlideRecord('sys_user_has_role');
hasRole.addQuery('user', users.sys_id);
hasRole.query();
while(hasRole.next()) {
gs.print(hasRole.getRowCount());
gs.print('********* sys_user_has_role ' + hasRole.role.name);
hasRole.deleteMultiple();
}
}
I have a given a try in my personal dev instance and it worked fine for me. Please modify the script if necessary.
Kindly let me know if that has worked and hit like or helpful based on impact.
Kind Regards,
Rajshekhar Paul