Scheduling a report for dynamic Recipients
Scheduling a report for dynamic Recipients based on the table column of the report
Introduction:
I have read some questions or queries on scheduling report for dynamic recipients based on the table column of the report. Also, I had few issues while working on the same requirements. Hence, I have start to write this article. I think it will help community users to work on this type of requirement in future.
Create scheduled report which will trigger based on conditions and send it to the dynamic receipts. Dynamic recipients may be assigned to users, assignee’s manager, etc.
Use case’s:
Create a scheduled report which will trigger based on some conditions and sent it to dynamic assigned to users.
Create a scheduled report which will trigger with conditions and send the incidents report to Managers of assignment group.
Create a scheduled report for send the assigned to users and his/her mangers for pending approval of requests.
Create a report and add the “assigned_to” or “assigned_to.manager” columns in the report.
Procedure:
Create a report and add the “assigned_to” or “assigned_to.manager” columns in the report.
Example- Create a report for example- incidents opened in last week with assigned to column in it.
Scheduled the same report run as on demand.
Create a scheduled script to update the dynamic assigned to list.
Here is the script: Step 5: For earlier versions of Orlando, the current object is working in scheduled job conditional script. we can directly used the below script in conditional option to dynamically update the recipients.
It will update the users list dynamically.
Check the mail logs.
Conclusion:
I this way, we can schedule a report a report with dynamic recipients.
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 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 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, assignee’s manager, etc.
Use case’s:
Create a scheduled report which will trigger based on some conditions and send it to dynamic 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 for 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 list.
Here is the script:
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;
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("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
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(senderArray); // unique elements
scheduleReport.user_list = finalRecipients.join(',');
// gs.log("User list: " +current.user_list);
scheduleReport.update();
SncTriggerSynchronizer.executeNow(scheduleReport); //execute schedule report
}
Step 5: For earlier versions of Orlando, the current object is working in scheduled job conditional script. we can directly used the below script in 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 users list dynamically and send the reports to recipients.
Check the mail logs.
Conclusion:
In this way, we can schedule a report with dynamic recipients.
In addition, to that we can use the following methods of mail script for report.
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 the CC users in notification
email.addAddress("to","sagar.pagar@testmail.com","Sagar Pagar"); // to add the To users in notification
email.addAddress("bcc","sagar.pagar@testmail.com","Sagar Pagar"); // to add the BCC users in notification
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.
Thanks,
Sagar Pagar
Comments
Post a Comment