The CreatorCon Call for Content is officially open! Get started here.

Using schedule to run job only at certain times

danenglish
Giga Expert

I'm trying to create a scheduled job that will run only at certain times.  In this case, I want it only to run weekdays, during business hours, and not on holidays.  All this job does is fire off an event that I can use to trigger a notification.

I've found some useful code, but it doesn't seem to be sticking to the schedule times, as I'm seeing the job kick off on weekends, etc.

Am I missing something?

 

checkInSchedule();

function checkInSchedule(){

var schedRec = new GlideRecord('cmn_schedule');

schedRec.get('8-5 weekdays excluding holidays');

if(typeof GlideSchedule != 'undefined')

var sched = new GlideSchedule(schedRec.sys_id);

var inSched = sched.isInSchedule(new GlideDateTime());

if(inSched){

return false;

}

else{

return true;

}

}

 

As always, any help is appreciated!

1 ACCEPTED SOLUTION

Mwatkins
ServiceNow Employee
ServiceNow Employee

Yeah... that's the problem. Normally, out-of-the-box, you can only run a scripted condition if the "advanced" checkbox has been checked on the Scheduled Job. However, when you install the "Scriptless Scheduled Jobs" application it exposes the Condition field even when the Advanced field has not been checked. This leads to a confusing situation where you can put something in the scripted condition field and it will be ignored. You actually can get what you want though, Dan. Do this:



  1. Leave your job exactly as it is right now (both the Conditions and Condition field filled out and all the other stuff for the Scriptless behavior)
  2. Click the "Advanced" checkbox (your Scriptless behavior fields will disappear but they will still work!)
  3. Save your changes


Now what will happen is that the platform will evaluate the script in the Condition field and if it evaluates to true then it will fire the ScriptlessScheduledJobUtils script include and the Conditions (u_conditions) field will be evaluated.


View solution in original post

20 REPLIES 20

Thank you. I'll look in to that.