ServiceNow Learning 36: Sending Scheduled Reporting to dynamic users in ServiceNow

Shamma Negi
Kilo Sage
Kilo Sage

Hi All,

 

Here is very common requirement wherein we need to send the scheduled report to dynamic users and that too multiple users.

 

So, the best option to achieve this requirement would be create one Scheduled Report and one Scheduled Job which helps us to update the dynamic users via script in Scheduled Job.

 

Here is the great example to achieve this.:

 

I think it will help community users to work on this type of requirement in the future.

Create a scheduled report which will trigger based on conditions and send it to the dynamic receipts. Dynamic recipients may be assigned to users, the assignee’s manager, etc.

 

Use cases:

  1. Create a scheduled report which will trigger based on some conditions and send it to dynamically assigned to users.
  2. Create a scheduled report which will trigger with conditions and send the incidents report to Managers of the assignment group.
  3. Create a scheduled report to send to the assigned_to users and his/her managers for pending approval of requests.

 

Here is the script:

updateDynamicRecipients();

function updateDynamicRecipients(){
	var scheduleReport = new GlideRecord('sysauto_report');  // glide the Scheduled report
	scheduleReport.get("sys_id of report"); //Sys ID of your schedule Report

	var recipients = [];
	var tablename = scheduleReport.report.table;
	var query = scheduleReport.report.filter;

	var gr = new GlideRecord(tablename);
	gr.addEncodedQuery(query);
	gr.query();
	while (gr.next()) {
		recipients.push(gr.assigned_to.sys_id.toString());  // push the assigned _to users in recipients array
	}
	// gs.log(recipients.toString());
	// gs.log(recipientsManager.toString());

	var arrayUtil = new ArrayUtil();
	finalRecipients = arrayUtil.unique(recipients);   // unique elements

	scheduleReport.user_list = finalRecipients.join(',');
	//	gs.log("User list: " +current.user_list);
	scheduleReport.update();

	SncTriggerSynchronizer.executeNow(scheduleReport); //execute schedule report

}

I found this article very helpful. I followed the steps and able to resolve my real time problem.

 

https://www.servicenow.com/community/platform-analytics-articles/scheduling-a-report-for-dynamic-rec...

 

Regards,

Shamma

Regards,Shamma Negi
1 REPLY 1

Yong Zeng Lee
Tera Contributor