Is it possible to share multiple (400+) reports to 3 users with a script?

Wilson Ochoa
Giga Contributor

Hey everyone,

So I was recently tasked with sharing 400+ reports created by 1 individual amongst 3 users. I am fairly new to service now and I am not too familiar with sharing reports or how to go about this. I am aware that you can share users 1 by 1, however with 400+ reports that could take a long time. I was hoping that I could use a script using a gliderecord that queries all of the reports that I am looking for and then being able to assign each users sysid to all reports that fit the query. If there are any other suggested ways to go about this I would really appreciate the help. I also have checked the article "Bulk sharing own reports" with no luck.

Thank you all,

Wilson

1 ACCEPTED SOLUTION

Thank you for the quick reply!

I played around with that code and found that the array wasn't working for some reason so I hard coded the 3 users and it worked fine. When I created a query for all the records I was looking for, I simply created 3 separate records within the sys_report_users_groups table that contained the user_id of each person and the report_id as the sys_id belonging to the sys_report that we are querying!

View solution in original post

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

When you share report with user, record is created in sys_report_users_groups table.

You can write below fix script to share multiple reports with 3 users

 

 

Regards,

Sachin

sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below fix script to share multiple reports with multiple users

 

var list = "62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a";// users sys_id list to whom you want to share report
var arr = list.split(",");
for(i=0;i<arr[i];i++){
	var rep = new GlideRecord('sys_report');
	rep.addEncodedQuery('title=Cost Plan Break Down');// add your encoded query to find multiple reports
	rep.query();
	while(rep.next()){
		
		var usr = new GlideRecord('sys_report_users_groups');
		usr.initilize();
		usr.user = arr[i];
		usr.report_id = rep.sys_id;
		usr.insert();
		
	}
}

 

Please run this script first in your NON-prod instance to verify results and then you can run in PROD.

 

Regards,

Sachin

Thank you for the quick reply!

I played around with that code and found that the array wasn't working for some reason so I hard coded the 3 users and it worked fine. When I created a query for all the records I was looking for, I simply created 3 separate records within the sys_report_users_groups table that contained the user_id of each person and the report_id as the sys_id belonging to the sys_report that we are querying!

Hi, I had to change the code for Orlance version to:

 

var list = "59e8d7b8db5f5f00aee4b5ca689619b0"; //user sys_id
var arr = list.split(",");
for(i=0;i<arr[i].length;i++){
	var rep = new GlideRecord('sys_report');
	rep.addEncodedQuery('titleSTARTSWITHo365');
	rep.query();
	while(rep.next()){
		var usr = new GlideRecord('sys_report_users_groups');
		usr.initilize();
		usr.user_id = arr[i];
		usr.report_id = rep.sys_id;
		usr.insert();
		
	}
}

 

Br, David