- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2015 09:56 PM
Hi all,
I'm looking to develop a weekly notification for all the on call support groups using the same format as the formatted on-call schedule report. Unfortunately, we have a large number of groups and schedules and running the on-call formatted schedule report for all groups will timeout.
Any good ideas of how to accomplish this "formatted on call report" without any risk of a timeout regardless of the amount of on call schedules or assignment groups?
Thanks,
Berny
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2015 11:16 AM
I was able to do this. In case it's helpful for anybody else, here's how i did it...
a) Created a schedule job that will be in charge of invoking an event that will trigger a notification
b) Within the notification I have a mail script that will pull all the assignment groups and will generate the html leveraging the same functions that the system uses to generate the scheduled report.
Here goes the code of the mail script:
var emailBody = onCallSchedule();
template.print(emailBody);
function onCallSchedule(){
var groups = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('JOINsys_user_group.sys_id=cmn_rota.group!active', '=', 'true');
gr.addOrderBy('name');
gr.query();
while (gr.next()) {
groups.push(gr.sys_id.toString());
}
var fsr = new FormattedScheduleReport();
fsr.buildSchedule(groups.join(','), gs.beginningOfThisWeek(), gs.endOfThisWeek());
var html = fsr.getReport();
return html;
}
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 10:01 AM
In case you need a guide to have your event and notification setup, the following should be helpful:
Events and Email Notification - ServiceNow Wiki
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 11:10 AM
Ok. Here are the four elements I built. It is still not kicking off when I click on "Execute Now" in the Scheduled Job. Do I need more code in the scheduled job script? Does something else look wonky? Do I need a business rule as well? Was I supposed to customize the Notification Email Script in some way? So many moving parts for a *simple* notification...
Scheduled Job Script:
gs.eventQueue("oncallschedule", current, gs.getUserID(), gs.getUserName());
Event Registry:
Event name: oncallschedule
Table: Roster [cmn_rota_roster]
Fired by: scheduled job
Notification Email Script:
Name: On_Call_Schedule_Report
Script:
var emailBody = onCallSchedule();
template.print(emailBody);
function onCallSchedule(){
var groups = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('JOINsys_user_group.sys_id=cmn_rota.group!active', '=', 'true');
gr.addOrderBy('name');
gr.query();
while (gr.next()) {
groups.push(gr.sys_id.toString());
}
var fsr = new FormattedScheduleReport();
fsr.buildSchedule(groups.join(','), gs.beginningOfThisWeek(), gs.endOfThisWeek());
var html = fsr.getReport();
return html;
}
Notification: ON Call Schedule
Table: Roster [cmn_rota_roster]
When to Send: Event is fired
Event Name: oncallschedule
Who will receive it:
Users: Pivec, Richelle
What it will contain:
Content Type: HTML Only
Subject: On Call Schedule Report
Body:
${mail_script:On_Call_Schedule_Report}
Thanks again for your help!
Richelle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 11:39 AM
Hi Richelle,
Your event definition and your notification should not have a table associated to them. That's the reason of why could be failing. Specially since you're passing current (which is an instance of the schedule job table, and it's different from the rota roster table which you're using in your event and notification definitions)
Here goes some other things to look at:
a) Make sure your instance is enabled to send notifications. You can confirm if other notifications are going out by navigating to System Logs >> Emails
b) Check if the event gets fired when you execute the scheduled job. You can validate this at System Policy >> Events >> Event Log
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 11:49 AM
That worked! I needed to remove the table from both the notification and the event.
I am in Dev, so I know that it won't send, but I can see that it queued up to send in the Email log and using an HTML translator, I am able to see what it would look like if it had sent.
Thanks much.
Richelle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2016 12:13 PM
Great!!
Thanks,
Berny