Fix script to add role to sys_ report table

nebiata
Tera Expert

Currently, about 450 reports are shared with users with itil role. I have a requirement to add an additional role so those reports will be shared with the user who has itil and this additional role. 

 

Thank you

1 ACCEPTED SOLUTION

It works for me,

See this is the script i ran

AnuragTripathi_0-1699456138786.png

 

 

And result

AnuragTripathi_1-1699456170230.png

 

-Anurag

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@nebiata 

you can try this sample script and run in background. Please test it for 5 reports and if it works then comment the setLimit(5) line of code

updateRoles();

function updateRoles(){
	try{
		var reportTitles = 'Catalog item translation coverage'; // give here the title of those 450 reports
		var gr = new GlideRecord("sys_report");
		gr.addQuery("title", "IN", reportTitles);
		gr.setLimit(5); // comment this after your testing
		gr.query();
		while (gr.next()) {
			gr.roles = gr.roles + ',maint';
			gr.update();
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

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