Notification to send during specific hours

Kiera Mears
Mega Guru

Hello!

 

We need to configure a notification (like a basic Out Of Office in Outlook) that sends between specific times. The idea is that if someone emails in at 8pm for example, they get the notification back to basically say "office hours are between 7am-7pm". However, it would also need to trigger all day on weekends.

I've been playing around with notifications and digging through the Community but can't quite find what I need!

Can anyone help with this?

 

Many thanks,

Kiera

7 REPLIES 7

Riya Verma
Kilo Sage
Kilo Sage

Hi @Patrick Laroch1 ,

 

create a business rule that will evaluate the conditions and trigger the notification. Navigate to the "Business Rules" module in ServiceNow and create a new business rule. Give it an appropriate name like "Office Hours Notification".

Within the business rule, define the conditions for triggering the notification. In this case, we want the notification to be sent if the incoming email is received outside the office hours during weekdays or anytime on weekends.

 

You can use below script for reference and modify it based on your requirement if you dont have time constraint in weekday:

(function executeRule(current, previous) {
  var currentDateTime = new GlideDateTime();
  var currentHour = currentDateTime.getHours();
  var isWeekend = (currentDateTime.getDayOfWeek() == 6 || currentDateTime.getDayOfWeek() == 0);

  if ((currentHour < 7 || currentHour >= 19) && !isWeekend) {
    // Trigger the notification here
    gs.eventQueue('notification.office_hours', current, current.recipient);
  }
})(current, previous);

then, create the notification which will be running when this event is triggered and define notification body.

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

I would probably still use a schedule instead of hardcoding so that if the schedule changes the admin does not have to modify code.
The scripts can be directly in the advanced condition of the notification instead of the BR.

Hi Riya,

I've tried doing this but it's not triggering the event by the looks of it. Any ideas?

 

Thanks,

Kiera