Firing Events from scheduled Jobs

sigmachiuta
Kilo Guru

I am trying to figure out the 'best' method to notify/ re notify if changed users of an activity.   I have another post where i was trying to do this with a workflow but I am thinking a scheduled job might be the safest bet.

I am trying to fire an event from a scheduled job when the follow up date is within 1 minute.   I am running the job every 2 minutes and I am checking if the notification field is within 1 minutes or less and the same field and its not greater than 2 minutes ago is there a better method of checking this notification field to trigger this scheduled job that fires off this email?

var gr = new GlideRecord('incident');

gr.addQuery('active', true);

gr.addQuery('state',4)

gr.query();

gr.next();

while(gr.next()){

if ('u_notification', '=<', gs.minutesAgo(1) && 'u_notification', '!=>', gs.minutesAgo(2)); {

//set state

gr.addQuery('state',1)

// Fire event to send email

gs.eventQueue("incident.notification", current)

};

}

6 REPLIES 6

Mike Allen
Mega Sage

You have to say gr.u_notification, not 'u_notification'.



You may want to look at creating a sys_trigger that will fire the event instead of the scheduled job.



Your set state would be


gr.state = 1;


gr.update();



gs.eventQueue("incident.notification", gr, null, null);



So,



if (gr.u_notification >=, gs.minutesAgo(1) && gr.u_notification <= gs.minutesAgo(2)); {  


 


//set state  


gr.state = 1;


gr.update();



// Fire event to send email  


gs.eventQueue("incident.notification", gr, null, null);


}



Or something like that.


bernyalvarado
Mega Sage

Hi,



In addition to what Mike already commented, make sure that the event: incident.notification is associated to the notification that you want to trigger.



Thanks,


Berny


I thought scheduled jobs were stored in the sys_trigger table.   I checked the table and the scheduled job is in the table.   is there something else i need to be looking at/missing?




Scheduled jobs set adrift


I explained how to set up a trigger here:



https://community.servicenow.com/message/814192#814192