Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to share bulk reports to groups?

User329467
Tera Expert

Hi,

I have a requirement to share bulk reports to groups. Is it possible with fix script? or?

How to achieve this?

Thanks,

Priyatham.

1 ACCEPTED SOLUTION

Here you go.

var groupsare=new GlideRecord('sys_user_group');
groupsare.addEncodedQuery('active=true');//Pass desired users query here 
//groupsare.setLimit(10); //uncomment to check for 10 records
groupsare.query();
gs.print(groupsare.getRowCount());
while(groupsare.next())
{

var sharereport=new GlideRecord('sys_report_users_groups');
sharereport.initialize();
sharereport.report_id.setDisplayValue('TimeCard Trend'); //Pass report name
sharereport.group_id=groupsare.sys_id;
sharereport.insert();
gs.print(sharereport.getRowCount());
}

 

If any of above comments helped you can kindly mark it as Helpful & also get the thread closed once you got things working.

View solution in original post

9 REPLIES 9

Jaspal Singh
Mega Patron
Mega Patron

Hi Priyatham,

 

There exists a Table: Report Users and Groups (sys_report_users_groups) that can be used.

You can write a script that will help you do the same.

var userare=new GlideRecord('sys_user');
userare.addEncodedQuery('active=true');//Pass desired users query here 
//userare.setLimit(10); //uncomment to check for 10 records
userare.query();
gs.print(userare.getRowCount());
while(userare.next())
{

var sharereport=new GlideRecord('sys_report_users_groups');
sharereport.initialize();
sharereport.report_id.setDisplayValue('TimeCard Trend'); //Pass report name
sharereport.user_id=userare.sys_id;
sharereport.insert();
gs.print(sharereport.getRowCount());

}

 

It can also be altered to make it work for Groups.

 

Hi Jaspal,

Thanks for the reply, can you make it for groups?

 

Here you go.

var groupsare=new GlideRecord('sys_user_group');
groupsare.addEncodedQuery('active=true');//Pass desired users query here 
//groupsare.setLimit(10); //uncomment to check for 10 records
groupsare.query();
gs.print(groupsare.getRowCount());
while(groupsare.next())
{

var sharereport=new GlideRecord('sys_report_users_groups');
sharereport.initialize();
sharereport.report_id.setDisplayValue('TimeCard Trend'); //Pass report name
sharereport.group_id=groupsare.sys_id;
sharereport.insert();
gs.print(sharereport.getRowCount());
}

 

If any of above comments helped you can kindly mark it as Helpful & also get the thread closed once you got things working.