Sharing Multiple Reports with Multiple Groups without Typing in Each Group Individually.

ellencarpen
Tera Contributor

I have a requirement of sharing 30 plus reports with 5 Users and 15 Assignment Groups. It is exhausting typing all 20 into every Share section of every report. I can't copy and paste. Is there any way that a non-administrator can select multiple reports and share it to the Users/Groups simultaneously OR a workaround the cut and paste? 

 

 

1 ACCEPTED SOLUTION

@ellencarpen 

Thank you for marking my response as helpful.

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@ellencarpen 

can you try this background script if you have the admin role? it will check if it's already shared or not.

If not then it will share with those users and groups

Note: Test this for 2 reports and verify

// give data into the array
var reportSysIds = ['reportSysId1','reportSysId1']; // give the report sysIds here

var userSysIds = ['user_sys_id_1','user_sys_id_1']; // give the user sysIds here

var groupSysIds = ['group_sys_id_1','group_sys_id_2']; // give the group sysIds here
// ======================================

// Function to check if a sharing record already exists
function sharingExists(reportId, userId, groupId) {
  var gr = new GlideRecord('sys_report_users_groups');
  gr.addQuery('report_id', reportId);
  if (userId) {
    gr.addQuery('user_id', userId);
  }
  if (groupId) {
    gr.addQuery('group_id', groupId);
  }
  gr.query();
  return gr.hasNext();
}

// Share with users
for (var i = 0; i < reportSysIds.length; i++) {
  var reportId = reportSysIds[i];

  for (var j = 0; j < userSysIds.length; j++) {
    var userId = userSysIds[j];
    if (!sharingExists(reportId, userId, null)) {
      var shareUser = new GlideRecord('sys_report_users_groups');
      shareUser.initialize();
      shareUser.report_id = reportId;
      shareUser.user_id = userId;
      shareUser.insert();
      gs.info('Shared report ' + reportId + ' with user ' + userId);
    } else {
      gs.info('Report ' + reportId + ' already shared with user ' + userId);
    }
  }

  // Share with groups
  for (var k = 0; k < groupSysIds.length; k++) {
    var groupId = groupSysIds[k];
    if (!sharingExists(reportId, null, groupId)) {
      var shareGroup = new GlideRecord('sys_report_users_groups');
      shareGroup.initialize();
      shareGroup.report_id = reportId;
      shareGroup.group_id = groupId;
      shareGroup.insert();
      gs.info('Shared report ' + reportId + ' with group ' + groupId);
    } else {
      gs.info('Report ' + reportId + ' already shared with group ' + groupId);
    }
  }
}

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

@ellencarpen 

Thank you for marking my response as helpful.

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