- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:42 PM
Hello!
I have a scheduled job that triggers an event to send a notification. It should trigger when the due date is one day from today aka tomorrow. The script in my scheduled job is
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery('active=true^short_descriptionLIKEFOR TESTING ONLY');
gr.query();
while (gr.next()) {
var end_date = new GlideDateTime(gr.request_item.due_date.getDisplayValue());
end_date.addDays(-1);
var today_date = gs.nowDateTime();
if (end_date == today_date) {
gs.eventQueue('event_name', gr, gs.getUserID());
}
}
Please help!
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:50 PM
you can also use encodedQuery
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery('request_item.due_dateRELATIVELT@dayofweek@ahead@1');
gr.query();
while(gr.next()) {
gs.eventQueue('event_name', gr, gs.getUserID());
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:48 PM
Hi,
update as below
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery('active=true^short_descriptionLIKEFOR TESTING ONLY');
gr.query();
while (gr.next()) {
var end_date = new GlideDateTime(gr.request_item.due_date);
end_date.addDays(-1);
var today_date = new GlideDateTime();
if (end_date.getNumericValue() == today_date.getNumericValue()) {
gs.eventQueue('event_name', gr, gs.getUserID());
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:50 PM
you can also use encodedQuery
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery('request_item.due_dateRELATIVELT@dayofweek@ahead@1');
gr.query();
while(gr.next()) {
gs.eventQueue('event_name', gr, gs.getUserID());
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 10:28 PM
Hi,
If the due date (once set) will not change, then use gs.eventQueueScheduled which can help to trigger an event on a specified date/time.
You can write an after update BR on your table with filter conditions
DueDate changes
and add this code.
var end_date = new GlideDateTime(current.request_item.due_date);
end_date.addDays(-1); //take one day before due date
gs.eventQueueScheduled("your_event",current,"","",end_date);
If the due date going to be updated, then go with scheduled job. Do not use getDisplayVAlue() when getting the date.
Mark the comment as correct/helpful if this helps to solve the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 10:29 PM
Also check out reminders feature of ServiceNow. This does not require any coding.
Mark the comment as correct/helpful if this helps to solve the problem.