Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

SCHEDULED JOB TO RUN EVERY SECOND ?

sukran
Giga Sage

Is this possible to run schedule job every second ? To check records and trigger a email event queue

 

I tried that but it's missed to do action for some record..

Or how to trim the date //Time field for second value so that we can try to run schedule job every minute...Is this right way ? Plz guide

12 REPLIES 12

You just need to run a BR on insert and update so when the planned date is set/updated the event is scheduled or updated.  Running a job means its going to constantly be querying when there is no work to do, which to me is a waist of processing time when a simple update is all that is needed.

One more question is coming into my mind is that if the scenario is like initially i set the end date as tomorrow and later changed to day after tomorrow then  with the first insert/update one event will be scheduled for tomorrow and one will be scheduled for day after tomorrow. So, for the same ticket twice a notification will be sent. The notification which would be sent tomorrow will be a spam. Please correct me if i'm wrong.

Kindly mark my answer as Correct and helpful based on the Impact.
Thanks and Regards,
Alok

Set the condition of the BR to planned date changes and active = true and planned date is not before today and have it run on insert/update and the below script should update the existing event or schedule a new one, but I did not test it.

var ev = new GlideRecord("sysevent");
ev.addQuery("instance", current.getValue("sys_id"));
ev.addQuery("name", "THE_EVENT");
ev.addNullQuery("processed");
ev.addQuery("state", "ready");
ev.query()
if(ev.next()){
   ev.setValue("process_on", current.planned_date);
   ev.update();
} else {
   //TRIGGER EVENT HERE
}