- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
09-09-2020 11:41 AM - edited 12-01-2022 04:30 AM
Introduction:
I have read some questions or queries on scheduling reports for dynamic recipients based on the table column of the report. Also, I had a few issues while working on the same requirements. Hence, I have started to write this article. 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:
- Create a scheduled report which will trigger based on some conditions and send it to dynamically assigned to users.
- Create a scheduled report which will trigger with conditions and send the incidents report to Managers of the assignment group.
- Create a scheduled report to send to the assigned_to users and his/her managers for pending approval of requests.
Procedure:
Need to follow the following procedure.
Step 1: Create a report and add the “assigned_to” or “assigned_to.manager” columns in the report.
Example- Create a report for example- incidents opened last week with assigned columns in it.
Step 2: Scheduled the same report run as on-demand.
Step 3: Create a scheduled script to update the dynamic assigned to the list.
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
}
Step 4: If need to include assigned _to Manager or assignment groups manager, then use the script.
updateUsersListWithManager();
function updateUsersListWithManager(){
var scheduleReport = new GlideRecord('sysauto_report'); // glide the Scheuled report
scheduleReport.get("42f87abc2f37201002454ae72799b66f"); //Sys ID of your schedule Report
var recipients = []; var recipientsManager = [];
var tablename = scheduleReport.report.table;
var query = scheduleReport.report.filter;
var reportgr = new GlideRecord(tablename);
reportgr.addEncodedQuery(query);
reportgr.query();
while (reportgr.next()) {
recipients.push(reportgr.assigned_to.sys_id.toString()); // push the assigned _to users in recipients array
recipientsManager.push(reportgr.assigned_to.manager.sys_id.toString()); // push the assigned _to managers in recipientsManager array
}
// gs.log("recipients array: " + recipients.toString());
// gs.log("recipients manager array: " + recipientsManager.toString());
var arrayUtil = new ArrayUtil();
arrayUtil.concat(recipients, recipientsManager);
var finalRecipients = arrayUtil.unique(recipients); // unique elements
// gs.log("finalRecipients: " + finalRecipients);
scheduleReport.user_list = finalRecipients.join(',');
// gs.log("User list: " + scheduleReport.user_list);
scheduleReport.update();
SncTriggerSynchronizer.executeNow(scheduleReport); //execute schedule report
}
Step 5: For earlier versions of Orlando, the current object is working in the scheduled job conditional script. we can directly use the below script in the conditional option to dynamically update the recipients.
updateDynamicRecipients();
function updateDynamicRecipients(){
var recipients = [];
// gs.log("current.report.filter:"+ current.report.table);
// gs.log("current.report.filter:"+ current.report.filter);
var scheduledGlideRecord = new GlideRecord(current.report.table);
scheduledGlideRecord.addEncodedQuery(current.report.filter);
scheduledGlideRecord.query();
while (taskQueryGR.next()){
recipients.push(scheduledGlideRecord.assigned_to + '' );
}
// gs.log(recipients.toString());
var arrayUtil = new ArrayUtil();
var finaRrecipients = arrayUtil.unique(recipients); // unique assigned to
current.user_list = finaRrecipients.join(',');
gs.log("User list: " +current.user_list);
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
if (senderArray.length > 0){
return true;
}
return false;
It will update the user's list dynamically and send the reports to recipients.
Check the mail logs.
In addition, to that, we can use the following methods of mail script for reports. We can specify copied and blind copied recipients by using the email object within a mail scripts.
email.setFrom("Servicedesk <servicedesk@testmail.com>"); // to set the setFrom mail address
email.setSubject("Subject of the report"); // to set the mail Subject for notification
email.addAddress("cc","sagar.pagar@testmail.com","Sagar Pagar"); // to add CC users in notification
email.addAddress("bcc","sagar.pagar@testmail.com","Sagar Pagar"); // to add BCC users in notification
Conclusion:
In this way, we can schedule a report with dynamic recipients.
Please provide your inputs and give suggestions if any. I would also like to hear a few use cases which I can build for you.
Feel free to mark helpful and bookmark this article.
Thanks,
Sagar Pagar
- 31,815 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Sagar Pagar , do you mind having a look at my question (just 3 posts up from the bottom)?
Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks. Problem resolved. The case can be closed now.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Sagar Pagar ,
Thank you for the article.
I have followed the steps which you have shared in the article to send the report to the assignment group's manager. And it is working good. Used the below script.
updateUsersListWithManager();
function updateUsersListWithManager() {
var scheduleReport = new GlideRecord('sysauto_report'); // glide the Scheuled report
scheduleReport.get("c4630ea21b394e144ff998e32a4bcb3f"); //Sys ID of your schedule Report
var recipients = [];
var recipientsManager = [];
var tablename = scheduleReport.report.table;
var query = scheduleReport.report.filter;
var reportgr = new GlideRecord('incident');
reportgr.addEncodedQuery(query);
reportgr.query();
while (reportgr.next()) {
//recipients.push(reportgr.assigned_to.sys_id.toString()); // push the assigned _to users in recipients array
recipientsManager.push(reportgr.assignment_group.manager.sys_id.toString()); // push the assigned _to managers in recipientsManager array
}
// gs.log("recipients array: " + recipients.toString());
gs.log("recipients manager array: " + recipientsManager.toString());
var arrayUtil = new ArrayUtil();
arrayUtil.concat(recipients, recipientsManager);
var finalRecipients = arrayUtil.unique(recipients); // unique elements
// gs.log("finalRecipients: " + finalRecipients);
scheduleReport.user_list = finalRecipients.join(',');
// gs.log("User list: " + scheduleReport.user_list);
scheduleReport.update();
SncTriggerSynchronizer.executeNow(scheduleReport); //execute schedule report
}
But Can we send individual reports to the managers with only their incident numbers instead of all?
Is that possible?
Thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Sagar Pagar ,
I followed above steps, however wanted to check if it is possible to send scheduled report. For example in my case i want to send list of CIs to owned by's manager. Catch is when i schedule the report. A manager should only receive extract of his owned by and should not receive the entire report. Is this possible? Does the script mentioned above work in this case?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for your quick response Sagar. This script is dynamically changing the recipients of the scheduled email, but it is not filtering the report (excel) for each recipient only for their relevant data.
All the recipients are getting the entire excel extract.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Sagar Pagar , will you please assist me in getting a report to dynamically send to the Assigned To, and the Manager of the Assignment Group of the tasks in the report?
Your script (below) works perfectly for updating the scheduled report users list with the Assigned To and the Assigned To's Manager. For our purposes, we want to send to the Assignment Group manager instead of the Assigned To's manager. For some reason, nothing I have tried has worked to get this to use the Assignment Group Manager (assignment group.manager).
updateUsersListWithManager();
function updateUsersListWithManager(){
var scheduleReport = new GlideRecord('sysauto_report'); // glide the Scheuled report
scheduleReport.get("70204d1b93734a100271f8fd1dba10eb"); //Sys ID of scheduled Report (not the 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()) {
recipients.push(gr.assigned_to.sys_id.toString()); // push the assigned _to users in recipients array
recipientsManager.push(gr.assigned_to.manager.sys_id.toString()); // push the assigned _to managers in recipientsManager array
}
// gs.log(recipients.toString());
// gs.log(recipientsManager.toString());
var arrayUtil = new ArrayUtil();
arrayUtil.concat(recipients, recipientsManager);
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
}
Thanks!
Any help would be greatly appreciated.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
HI @Sagar Pagar
Thank you for the help. I followed the steps but its not working. Request help.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi friends,
Did anyone found a way to send the scheduled report individually to each manager and the report containing only their subordinates?
I followed all steps @Sagar Pagar provided and is working, but in our case, the report is on the User table, we need managers to provide an update to their contractors and the scheduled report is being sent to ALL managers, in our case, more than 100 managers.
The report is being sent attached in an Excel format which is not productive for the managers as we need them to quickly look the report and reply to us with an update.
Any idea how to manage this?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Guyz,
I tried the same script to send the email to assigned_to, even tried to create list type report but it seems not working.
Can someone check the code below and suggest. requirement is simple send the scheduled email to incident assigned_to person.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Sagar Pagar,
Thanks for the post. It worked for me. I can see user's list adding in the "Users" field of the scheduled report. But when the email triggers the added users are adding in the 'To' list. Can we add these users in the BCC list?
Any others ways are there to add these dynamic users in the BCC of the scheduled report?
Regards,
Dhanakoddi
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Dhanakoddi2 - Yes. We can add users in BCC lists via email notification scripts in notifications.
You can try by
i. triggering event via eventQueue() method in scheduled job scripts.
ii. Get the event parameters in email scripts and call email scripts on scheduled report notification.
gs.eventQueue('event.name', gliderecordObject, usersLists); // Trigger event
email.addAddress('bcc', usersLists); // to add BCC users in notification
${mail_script:email.script.name}
Thanks,
Sagar Pagar
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Expected Result: I am trying to set up an email notification system that triggers an email to the task assignee and their manager if a change task is pending for more than 3 days. The email should contain all pending change task details in an Excel sheet. If there are multiple change tasks with different assignees, separate emails should be sent to each assignee with their respective pending task details.
Currently, one email is being sent to all assignees with all pending change task details." how to achieve?
- « Previous
-
- 1
- 2
- Next »