Send Notification 30Min before Due Date of Incident

Mark Wood
Tera Contributor

Hello Experts,

I want to send a notification 30 min before the due time of the incident. I have written the below script in the scheduled job but it's not working..

var gr=new GlideRecord("incident");
gr.addNotNullQuery('due_date');
gr.query();
while(gr.next())
{
	var min=30;
var gdt=new GlideDateTime(gr.due_date);
gdt.addSeconds(-(min*60));
gs.log(gdt);
gs.eventQueueScheduled('demo',gr,"Demo","Demo",gdt);

}

please guide me as to why this script is not working thank you.

 

4 REPLIES 4

Martin Ivanov
Giga Sage
Giga Sage

Would you please tell us do you have the events logged and what is in the time of execution parameter?

One possible issue can be the differene in the time zones. The due date that you see in your incident is adjusted to your time zone, while calling it via script you will get it in the time zone of the server.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

var gr=new GlideRecord("incident");
gr.get('892282ce973a6110df62b3b6f053af0b');
//gr.addNotNullQuery('due_date');
gr.query();
while(gr.next())
{
	var min=2;
var gdt=new GlideDateTime(gr.due_date);
gdt.addSeconds(-(min*60));
gs.log("Scheduled JOb Run Status"+gdt.getDisplayValueInternal());
gs.eventQueueScheduled('Demo',gr,gr.assigned_to,gr.assignment_group,gdt.getDisplayValueInternal());




}

Hello @Martin Ivanov ,

I have updated my script, and it's working but the event gets fired every time. I have attached a screenshot of the event log. it should fire only once that is before 2 min of due time.

 

 

The fifth parameter of eventQueueScheduled expects a GDT object. You are passign a display value, which I would assume is a string. This way you want to execute a scheduled event, but i doesn't get what it expects, and most probably the default behaviour in such case is to initialize a new GDT, which is automatically set to NOW. That is why the execution time matches perfectly the time of the event creation.

 

Another thing you must to is compare the time of execution of the scheduled job against the due date.

example with pseudo code

 

Create new gdt variable (do not pass parameter, it will initilize as now, the time of the job execution)

find the incidents with due date,

iterate through the incidents and compare the due date value against now (eg. if due date minus now is less than 30 mins AND there is no other event logged for this particaular incident (you will need to query the eventlog table to see this), fire the event.

 

in this scenario you don't even need eventQueueScheduled, you can do it with a regular event.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

@Mark Wood if my guidance has helped you resolve your issue, please consider makring it Correct. Thanks


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024