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

Hi Rams,

 

I have to create a reminder notification on HR case table.

For example: If I was assigned a case on Monday 1st June and the State is “Ready “or “Work in Progress” .

I would receive a reminder on the 5th business day after it’s been opened (6th July) and again 2 days after that (Wednesday, 8th July).

I would continue to receive the reminder every 2 business days until the State is changed to “closed complete”, “closed incomplete” or “suspended”.

 

find_real_file.png

 

What shall i add in created condition here to trigger the 1st 5th day notification.

Please suggest something , how this can be achieved.

Hi @Ram Singh -

Would this work with a database view? I have a database view that joins the incident and journal entry tables. I followed what you mentioned above step by step using the database view as my table and am getting an error for my event in the event log. I ran my query as a background script and am getting an undefined error even though I am getting results when I query the table, and I double checked to copy and paste the query multiple times.

Can you please assist me with this?

Below is my code in my scheduled job:

var gr = new GlideRecord('u_dv_nreca_inc_comment_7day');
gr.addEncodedQuery('i_stateIN1,2,3^j_sys_created_onISEMPTY^i_sys_created_onRELATIVELT@dayofweek@ago@5^i_due_dateRELATIVELT@dayofweek@ago@1');
gr.query();
while (gr.next()) {
    gs.eventQueue("incident.nocomment", gr);
}

What is the condition builder to be used specify - 50 days prior to a particular date in encoded query.

It is really helpful

Nilanjan1
Mega Sage

Hello All, 

I was going through the post and it seems to be very helpful, I am also trying to create a kind of a notification which triggers every year on a list of cloud applications. I created a scheduled jobs and an event and a notification, however when the execute a scheduled job the firing of the event or the notification is not happening. Any leads to this. this is what I have used as a steps: 

 

var gr = new GlideRecord('u_cloud_applications');
gr.addEncodedQuery('u_business_ownerISNOTEMPTY');
gr.query();
while(gr.next()){
	gs.eventQueue('Cloud Application Notification',gr);
}

cloud application notification is the Event. 

Regards

Nilanjan