I want to remove the particular user role from bulk reports.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2025 11:14 PM
I want to remove the particular user role from bulk reports. I tried using background script to remove the roles but it is not working. can someone please help me out on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2025 11:21 PM
Try below script in background with some modifications as per your requirement .
And see if it works or not.
// Replace 'role_to_remove' with the actual sys_id of the role you want to remove
var roleToRemove = 'role_to_remove';
// Query all reports with the role
var reportGR = new GlideRecord('sys_report');
reportGR.addQuery('roles', 'CONTAINS', roleToRemove);
reportGR.query();
while (reportGR.next()) {
var roles = reportGR.roles.toString().split(',');
// Remove the role from the list
var updatedRoles = roles.filter(function(role) {
return role !== roleToRemove;
});
// Update the report with the modified role list
reportGR.roles = updatedRoles.join(',');
reportGR.update();
gs.print('Updated Report: ' + reportGR.getValue('name') + ' | Roles: ' + reportGR.roles);
}
gs.print('Role removal completed.');
I hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2025 11:37 PM
what script did you write? please share that
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader