Creating Schedule job to send notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2019 12:15 PM
Hi,
I have to create a scheduled job which will run daily to send a notification to the caller of the incident, if the ticket is in active state for more than 5 days.
Below is the script I have written in the Schedule job-
var gr = new GlideRecord('incident');
gr.addQuery('state', 'Active');
gr.addQuery('sys_created_on', '<', gs.daysAgo(5));
gr.query();
while(gr.query()){
gs.eventQueue('Incident.Active',gr, '','');
}
I have registered an event called Incident.Active and created a notification. I have not added any condition/script in the notification.This is not working though. Can someone please explain me my mistake?
I am very new to Servicenow and any help is appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2019 02:53 PM
You do no need to write script for this requirement.
Please follow below to configure scheduled job to send reminders.
https://community.servicenow.com/community?id=community_blog&sys_id=ae9caee1dbd0dbc01dcaf3231f96193d
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2019 07:03 AM
Hi,
thanks Sachin but I need to do this via scripting.
Below is the script I have written in the Schedule job-
var gr = new GlideRecord('incident');
gr.addQuery('active', 'true');
gr.addQuery('sys_created_on', '<', gs.daysAgo(5));
gr.query();
while(gr.query()){
gs.eventQueue('Incident.Active',gr, '','');
}
I have created the event called Incident.Active and a notification. I have not added any condition in the notification. Can you please point out my mistake?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2019 12:26 PM
Hi RamS,
Thanks for the reply I understand it now. I have created an event Incident.Active and created the Notification where I selected the event.
I have written the following code in Schedule Job, but it is not working. Can you help with what is the mistake?
var gr = new GlideRecord('incident');
gr.addQuery('state', 'Active');
gr.addQuery('sys_created_on', '<', gs.daysAgo(1));
gr.query();
while(gr.query()){
gs.eventQueue('Incident.Active',gr, '','');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2019 10:46 AM
YOu can pass event parameters
Modify your code like below
var gr = new GlideRecord('incident');
gr.addQuery('state', 'Active');
gr.addQuery('sys_created_on', '<', gs.daysAgo(1));
gr.query();
while(gr.query()){
gs.eventQueue('Incident.Active',gr,gs.getUserName(),gs.getUserID());
}
Also, first run your script in background script first to print if you are getting any record with your query.
Regards,
Sachin