Notification- Including Report

jyothi15
Tera Expert

Hi All,

 

I have certification task on cert_table assigned to a particular group . I need to create a report on the task that are not closed . I created a report for this. Now I need to send the report monthly via email to the group director. Can someone help me on this? If we need to send the report via schedule job can someone help me with the script to include the report in the notification.

1 ACCEPTED SOLUTION

jyothi15
Tera Expert

I used below script by seeing the article Scheduling a report for dynamic Recipients based o... - ServiceNow Community. It worked for  me.

updateUsersListWithManager();

 

function updateUsersListWithManager() {

var scheduleReport = new GlideRecord('sysauto_report'); // glide the Scheuled report

scheduleReport.get("6aa5bbe11b512990aa61fe6fdc4bcb5a"); //Sys ID of your schedule Report

 

var recipients = [];

var recipientsManager =[];

var tablename = scheduleReport.report.table;

var query = scheduleReport.report.filter;

 

var gr = new GlideRecord(tablename);

gr.addEncodedQuery(query);

gr.query();

while (gr.next()) {

recipientsManager.push(gr.assignment_group.u_director.sys_id.toString()); // push the assigned _to managers in recipientsManager array

}

 

var arrayUtil = new ArrayUtil();

finalRecipients = arrayUtil.unique(recipientsManager); // unique elements

scheduleReport.user_list = finalRecipients.join(',');

 

scheduleReport.update();

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

 

}

View solution in original post

2 REPLIES 2

J_31
Kilo Sage

If you want to schedule the report to be sent via email in ServiceNow, you can use the Scheduled Reports feature. Here's how you can set it up:

Go to Reports > Scheduled Reports.

Click New to create a new scheduled report.

Enter a Name for the scheduled report.

Select the Table for the report. In this case, it would be cert_table.

Select the Report Definition that you created for the report of open certification tasks.

Under the Schedule section, select Monthly as the frequency and specify the day and time you want the report to be sent.

Under the Email section, enter the email address of the group director in the Recipients field.

Check the box next to Attached in the Email section to include the report as an attachment.

Click Save.

Now the report will be sent to the group director's email address every month at the specified time. You can modify the report definition if you need to change the content of the report, and you can modify the scheduled report if you need to change the frequency or recipients.

jyothi15
Tera Expert

I used below script by seeing the article Scheduling a report for dynamic Recipients based o... - ServiceNow Community. It worked for  me.

updateUsersListWithManager();

 

function updateUsersListWithManager() {

var scheduleReport = new GlideRecord('sysauto_report'); // glide the Scheuled report

scheduleReport.get("6aa5bbe11b512990aa61fe6fdc4bcb5a"); //Sys ID of your schedule Report

 

var recipients = [];

var recipientsManager =[];

var tablename = scheduleReport.report.table;

var query = scheduleReport.report.filter;

 

var gr = new GlideRecord(tablename);

gr.addEncodedQuery(query);

gr.query();

while (gr.next()) {

recipientsManager.push(gr.assignment_group.u_director.sys_id.toString()); // push the assigned _to managers in recipientsManager array

}

 

var arrayUtil = new ArrayUtil();

finalRecipients = arrayUtil.unique(recipientsManager); // unique elements

scheduleReport.user_list = finalRecipients.join(',');

 

scheduleReport.update();

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

 

}