Trigger a Business Rule to setup 2 followup events

Rakesh40
Tera Contributor

Hello Everyone

 

I want to trigger a notification for incident which is not closed which "Due date" is past 5 days the notification should trigger 1st time. after the again second notification should trigger after 10 days for those which are still not closed.

When incident ticket is created trigger a business rule to setup 2 events in 'sysevent' table.

 

Notification should be triggered to Assiged to if "Due date" date is passed by 5 days and 10days.

 

If the Incident ticket is closed during all notification process, I want to cancel the pending event from the event queue.

 

Please help me with this script.

 

 

 

(function executeRule(current, previous /*null when async*/ ) {

//1st notification for 5days 
    var oneDayOverdue = current.due_date < gs.daysAgo(5);
    if (oneDayOverdue) {
        var event1 = new GlideRecord('sysevent');
        event1.initialize();
        event1.insert();
        gs.eventQueue('incident_due_date_overdue_5', '', '');
    }

//2nd Notification for 10days
var oneDayOverdue = current.due_date < gs.daysAgo(10);
    if (oneDayOverdue) {
        var event1 = new GlideRecord('sysevent');
        event1.initialize();
        event1.insert();
        gs.eventQueue('incident_due_date_overdue_10', '', '');
    }
   
    //Incident closed cancel all the queued events
    if (current.state == '6') {
        var eventGR = new GlideRecord('sysevent');
        eventGR.addQuery('state', 'ready');
        eventGR.query();
        while (eventGR.next()) {
            eventGR.state = 'error';
            eventGR.update();
        }
    }


})(current, previous);

 

 

 

Thanks

 

 

1 REPLY 1

Kieran Anson
Kilo Patron

The requirement doesn't make sense, particularly this line 

When incident ticket is created trigger a business rule to setup 2 events in 'sysevent' table.

 

However, an easier solution would be a flow with a wait condition. Incidents don't usually have a due date? You should be using SLAs to manage an incidents lifecycle and then triggering notifications/actionable work once an SLA surpasses its breach point