- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 03:41 PM
Hello,
Looking for some guidance on how to do this. The goal is to send a different email notification to incidents created after hours. The notification will basically say we will review incident next business day. Hoping to get some help on scripting this.
I would probably need to create the following. Unless if can recommend other way of doing it. Best practice???
Event to trigger notification
Business Rule
Notificaition
Thank You,
Edwin
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2016 01:21 PM
You will have to change this to send when an event is fired. Register a new event and change this notification to go out when that event is fired. In your existing business rule add an else condition
var sched = new GlideSchedule('sys_id of your schedule goes here');
var d = new GlideDateTime(current.opened_at);
if (sched.isInSchedule(d)) {
gs.eventQueue('event name',current,current.caller_id);
}
else{
gs.eventQueue('event name 1',current,current.caller_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 03:54 PM
Hi Edwin
I did with a similar approach, but add a schedule so whenever the business rule schedule the event on the next second, it will automatically go to the start of next business day
Having the business rule in there means you can specify exceptions for high priority incidents to be sent outside of business hours as well
- Event to trigger notification
- Notification
- Schedule for business hour
- Business rule to trigger event based on the business hour schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 04:02 PM
Hi Nam,
Thanks for the reply back. We have a after hour support schedule which i am using to trigger this notification. Are you using a custom script to tie this all together? Do you mind sharing?
Edwin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 04:35 PM
Hi Edwin
Unfortunately, I haven't got access to the old script anymore, but you can check out this link here for calculation
and event scheduling here
Notification Examples - ServiceNow Wiki
Here is a fix script I've just created to demonstrate how the business rule can run:
//in your business rule the "now" variable can be replaced with current.sys_updated_on
//just simulating a real record here
var current = new GlideRecord("incident");
current.query("active",true);
current.next();
var now = new GlideDateTime();
dateExample(now,current);
now.setDisplayValue("2016-09-27 19:00:00");
dateExample(now,current);
//this bit is what actually in the Business Rule
function dateExample(now,current){
var dc = new DurationCalculator();
dc.setSchedule("08fcd0830a0a0b2600079f56b1adb9ae");
dc.setStartDateTime(now);
dc.calcDuration(1);
gs.eventQueueScheduled("incident.notify", current, now.getDisplayValue(), dc.getEndDateTime().getDisplayValue() , dc.getEndDateTime());
//don't really need the next two lines either
gs.print("Start: " + now.getDisplayValue());
gs.print("Event Scheduled: " + dc.getEndDateTime().getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 06:03 PM
Here you go. Use GlideSchedule instead of durationcalculator. Create an after business rule and log the event from the business rule which in turn fires the notification based on the event.
When: after insert
Script:
var sched = new GlideSchedule('sys_id of your schedule goes here');
var d = new GlideDateTime(current.opened_at);
if (sched.isInSchedule(d)) {
gs.eventQueue('event name',current,current.caller_id);
}
Events and Email Notification - ServiceNow Wiki