- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 05:33 AM
Hi. I am trying to set up an email notification that will be sent to the assignee of a change 15 Minutes prior to the planned start date. To do this I've attempted to create a Scheduled Job that runs hourly, checks for records where the planned start date is 15 Minutes away and then creates an Event. The event should then trigger the email notification. However, I'm having trouble figuring out how to work out the '15 Minutes from now' part. When i filter it out, it shows all the upcoming changes. Not only the ones which is going to start in 15 minutes time.
This is my script in the Scheduled Job:
var gr = new GlideRecord('change_request');
gr.addActiveQuery('active', 'true'); //It will fetch all Active Records
gr.addEncodedQuery('start_dateRELATIVEGT@minute@ahead@15');
gr.query();
while(gr.next()) {
gs.eventQueue("change.remainder", gr, "", "");
}
Solved! Go to Solution.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 05:45 AM
Hi,
Try like this.
var gr = new GlideRecord('change_request');
gr.addActiveQuery('active', 'true'); //It will fetch all Active Records
gr.query();
while(gr.next()) {
var gdt = new GlideDateTime(gr.start_date);
gdt.addSeconds(-900);
var gdt1 = new GlideDateTime();
if(gdt.equals(gdt1)) {
gs.eventQueue("change.remainder", gr, "", "");
}
}
Or , you can try another approach.
In the BR after insert, trigger a event like below.
var gdt = new GlideDateTime(current.start_date); //put actual field name
gdt.addSeconds(-900);
gs.eventQueueScheduled("change.remainder", current, "", "",gdt);
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:30 AM
Okay. try this code.
And also check with the change request whose start date is in next 15 or 20 minutes. As per logs, the start date of CR that you get is 2013.
var gr = new GlideRecord('change_request');
//gr.addActiveQuery('active', 'true'); //It will fetch all Active Records
gr.addQuery("sys_id","put any change request sysid whose start is in 15 minutes");
gr.query();
while(gr.next()) {
var gdt = new GlideDateTime(gr.getValue("start_date"));
gdt.addSeconds(-900);
gs.log("Start date and time is "+gdt);
var gdt1 = new GlideDateTime();
gs.log("Current date and time is "+gdt1);
if(gdt.equals(gdt1)) {
gs.log("Entered into the if condition");
gs.eventQueue("change.remainder", gr, "", "");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 07:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 08:32 AM
Hello Imran,
As per the logs, the current dat and time was 2020-05-19 14:10:00 and your starte date is 2020-05-19 14:13:00
So i assume that the script might have worked after 3 mins.
Check out the logs further and you shall find the log which entered into if condition.
If it entered if condition, then go to event logs and check if event is triggered or not.
Mark the comment as helpful if it helps to debug the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2020 01:26 AM
Hi Asif.. I don't see any log or event log for this event trigger.