Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Creating Schedule job to send notification.

prabhmeet
Giga Expert

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. 

17 REPLIES 17

sachin_namjoshi
Kilo Patron
Kilo Patron

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

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?

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, '','');
}

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