- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 08:09 AM
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!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 10,881 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 04:06 PM
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:
- 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)
- Click the "Advanced" checkbox (your Scriptless behavior fields will disappear but they will still work!)
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2017 09:46 AM
Thanks, I'll give it a shot. I didn't realize the job would run regardless of the conditions, that might be part of my problem as I'm trying to validate the code with the scheduled jobs list.
The Run this script field is what populates automatically from the conditions that were put in prior to checking the advanced tab... so I'm not too familiar with that but ideally it should perform the same action(s) as when advanced is not checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2017 10:00 AM
The Run this script field gets auto populated based on the things you select in the Scriptless fields (event name, table, field list etc.) That is the way the Scriptless Scheduled Jobs application works. In the background it is writing the script for you based on the selections you make.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2017 10:08 AM
Good news, it looks like selecting advanced did take care of the problem. I changed the interval to 5 minutes and reduced my schedule down to 10 minutes. The first time the job ran and fired the event, I received notifications. The second time it ran outside of the schedule, I did not receive the same notifications.
I think I'm good to go. Appreciate all the help on this... as a low-coder the SSJ application is a lifesaver, but this was the first time I ran into an issue with it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 10:14 AM
Thanks for helping out with supporting this. If anyone has recommendations how I can make the app better, I'm open. Perhaps we can talk in person at K17! Ping me if you want a meet up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 10:18 AM
Hey Chuck! Love the SSJ app. First time I've had an issue and it appears to simply be that you can't have a scripted condition and filter conditions at the same time without switching to advanced view... just something to note, really.