Incident Notification for After Hours Requests
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 10:40 AM
We have a team that receives requests via email. They operate during our core business hours only. We are looking for a way to send a "request received" notification based on if the email is created during core business hours or after business hours.
We've created three schedules, "core hours", "after hours", and "weekend".
I've seen a post on how to do this, but it's convoluted and confusing, and several years old. Is there a proper method to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 12:55 PM
I've got the inbound action set but wasn't sure how to implement checking against the schedules. Unfortunately i'm very much a novice with this.
So i should add an event to the registry and then set up a notification triggered on that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2024 07:04 AM
Is there a step-by-step guide on how to do this somewhere?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 07:48 AM - edited 09-28-2024 07:52 AM
Hi @JHufford ,
Sorry, somehow my answer wasn't added to the thread.
So for this you will need to create in the event registry, events or event for notification, since you don't have that much experience I would say you to create 3 events for 3 different notifications (working hours, non-working hours, end of week) and then you can easily change this to 1 event if needed.
Then you will need to trigger it in the input action, I would do this at the end with code similar to this:
var current_date = new GlideDateTime();
if (current_date.getDayOfWeekLocalTime() < 6) {
var gt = new GlideTime();
gs.info(gt.getDisplayValue());
gs.info(gt.getHourOfDayLocalTime());
if (gt.getHourOfDayLocalTime() < 18 && gt.getHourOfDayLocalTime() >8 ) {
gs.eventQueue("business hours event here");
} else {
gs.eventQueue("non business hours event here");
}
}else{
gs.eventQueue("Weekend event here");
}
The code can be adapted to your specific needs, but in short, what it does is check the day of the week, then if it is on a business day, it validates the time of day and triggers the notification event according to the time.
This can be quite different as the eventQueue can take parameters and the time can also be managed differently.
Let me know if you still need any help.
Best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2024 08:15 AM
Hi,
You can achieve this by using ServiceNow’s **Schedule API** in a Business Rule. Here’s a streamlined approach to meet your requirement:
### Steps:
1. **Create a Business Rule** on the `sys_email` table to run **after insert**.
2. In the Business Rule, use the following script to check whether the email was received during core hours, after hours, or on the weekend based on your predefined schedules:
```javascript
(function executeRule(current, previous /*null when async*/) {
// Replace with the sys_ids of your schedules
var coreSchedule = new GlideSchedule('sys_id_of_core_hours_schedule');
var afterHoursSchedule = new GlideSchedule('sys_id_of_after_hours_schedule');
var weekendSchedule = new GlideSchedule('sys_id_of_weekend_schedule');
var emailReceivedTime = new GlideDateTime(current.sys_created_on); // Email creation time
var isCoreHours = coreSchedule.isInSchedule(emailReceivedTime); // Check if it's core hours
var isWeekend = weekendSchedule.isInSchedule(emailReceivedTime); // Check if it's the weekend
// Fire appropriate event based on the schedule
if (isCoreHours) {
gs.eventQueue('request.received.core.hours', current, current.recipient, current.subject);
} else if (isWeekend) {
gs.eventQueue('request.received.weekend', current, current.recipient, current.subject);
} else {
gs.eventQueue('request.received.after.hours', current, current.recipient, current.subject);
}
})(current, previous);
```
3. **Set up Notifications** based on these events (`request.received.core.hours`, `request.received.after.hours`, `request.received.weekend`) to send different responses based on when the email was received.
This script will ensure that your team receives the appropriate notification depending on whether the email was received during core hours, after hours, or the weekend.
Let me know if you need further clarification.
Best regards,
R.S