trigger a notification on the change_request if the Planned End Date has only 3 hours remaining

Saurav Bhardwa2
Tera Contributor

Hello,

I'm looking for a solution to trigger a notification on the change_request when the Planned End Date is only 3 hours away. I have tried using GlideDateTime, subtracting time, and gs.eventQueueScheduled, but I seem to be missing something each time. I want to ensure that the notification only triggers if the Change Request is not closed, even if I schedule an event, and the user completed the change, he will still receives the notification. We only want notification to trigger if the state is not closed complete. Could someone please assist me in achieving this?

6 REPLIES 6

Hello, below is the script I am using. I don't know but it's always leaving the processed date empty in the Event logs

(function executeRule(current, previous /*null when async*/ ) {
   
var gr1 = new GlideRecord('sysevent');
    gr1.addQuery('state', 'ready'); // We only want the event in the ready state
    gr1.addQuery('name', 'notify.change.assignee.beforeBreach'); // Change the event name to the event name you are using
    gr1.addQuery('table', 'change_request');
    gr1.addQuery('instance', current.sys_id + ''); // Get the event that has been created for this record
    //gr1.setLimit(1); // Assuming there is only one ready event active for this record at a time, this can improve performance
    gr1.deleteMultiple();
    
var end = current.end_date;
    var endDateTime = new GlideDateTime(end);
    endDateTime.subtract(7 * 60 * 60 * 1000);
 
    var updatedEnd = endDateTime.getDisplayValue() + '';
 
    var gdt = new GlideDateTime(updatedEnd) + '';
    gs.info('checkValue  ' + updatedEnd + '-- ' + gdt);
    gs.eventQueueScheduled('notify.change.assignee.beforeBreach', current, current.assigned_to, 'test', updatedEnd);
 
/*var event = new GlideRecord('sysevent');
event.addQuery('state', 'ready'); // We only want the event in the ready state
    event.addQuery('name', 'notify.change.assignee.beforeBreach'); // Change the event name to the event name you are using
    event.addQuery('table', 'change_request');
    event.addQuery('instance', current.sys_id + '');
event.query();
event.setValue('processed' , updatedEnd);
event.update();*/
 
 
 
    if (current.status == 8 || current.status == 9) {
        var gr = new GlideRecord('sysevent');
        gr.addQuery('state', 'ready'); // We only want the event in the ready state
        gr.addQuery('name', 'notify.change.assignee.beforeBreach'); // Change the event name to the event name you are using
        gr.addQuery('table', 'change_request');
        gr.addQuery('instance', current.sys_id + ''); // Get the event that has been created for this record
        gr.setLimit(1); // Assuming there is only one ready event active for this record at a time, this can improve performance
        gr.deleteMultiple();
    }
 
})(current, previous);

ersureshbe
Giga Sage
Giga Sage

Hi,  You can achieve it through code. The below email functions are OOB. But, in your business rule you should validate the planned End Date with the current time using date/time functions.

 

email.setFrom("umassmeddev@service-now.com");

email.setReplyTo("robert.poschmann@umassmed.edu");

email.setSubject("This is the new subject line");

email.setBody("This is the new body");

Regards,
Suresh.