I want to remove the particular user role from bulk reports.

shaikimran4
Tera Contributor

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.

2 REPLIES 2

Ct111
Giga Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@shaikimran4 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader