Send Email Notification when Incidents created after hours

etobia
Kilo Expert

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

1 ACCEPTED SOLUTION

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);


}


View solution in original post

39 REPLIES 39

Yeah..i caught that. I revised it and it appears to work. Just need to test it more.


Brian Dailey1
Kilo Sage

Hi Edwin,



I'm not sure why you would go to all the trouble and complexity of trying to setup a business rule to manage and try to coordinate events between notices, when you can just setup two notifications (one for your regular 'Incident Opened', and one for 'Incident Opened After-Hours'), and include a script in each one to check the schedule and either send/not send.   To do so, make sure you click the "Advanced View"   link on the notification, so that you can see the 'Advanced Condition' script field on the 'When to send' tab.



First, set your notices to fire when a "Record is inserted or updated", and select only the "Inserted" check box.



Next, you will use a script similar to what Abhinay provided for your business rule, except that:


  1. It will set the variable 'answer' to either true/false.
  2. You will need to flip-flop the logic for one of the scripts so that they are complimentary.


Here are your scripts:


  • For the Incident Opened After-Hours notification:

var sched = new GlideSchedule('sys_id for normal operations schedule');


var d = new GlideDateTime(current.opened_at);


if (sched.isInSchedule(d)) {


answer = false; //DO NOT send this after-hours notice if we are currently in-schedule


}


else{


answer = true;


}



  • For the Incident Opened notification:

var sched = new GlideSchedule('sys_id for normal operations schedule');


var d = new GlideDateTime(current.opened_at);


if (sched.isInSchedule(d)) {


answer = true; //SEND this regular notice if we are currently in-schedule


}


else{


answer = false;


}



And here is how your notifications should look:



After-hours Notification:


INC_notice_1.png




Regular Notification:


INC_notice_2.png





I think that would be a easier solution for you, and simpler to maintain.




Thanks,


-Brian


Hi Brian,



Thanks for your feedback and would certainly keep this in mind moving forward. Finally got this thing to work using just 1 BR to trigger one or the other of the notifications i created. I appreciate this other solution you have included in this thread.



Edwin


Sure, no problem.



-Brian


Hi Brian,

I recently came across your post when looking for a solution to this requirement.  I setup two email notifications, just as you show.  However, the email that is not supposed to be sent, shows up in the email logs as being sent during the in-schedule time.  Any idea where else I can look to troubleshoot?