Scheduled job condition not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 06:35 AM
I wonder if anyone can help with this. I have a scheduled job that I want to run on the 1st of each quarter. I've created a condition script that looks like this:
var answer = false;
var now = new Date();
var month = now.getMonth();
if (month == 0 || month == 3 || month == 6 || month == 9) {
answer = true;
}
answer;
When the above is run as a background script it works. I can output answer at the end and see that it is correctly calculated.
However with the scheduled job, which was meant to run on 1st October, the job didn't trigger (it's meant to create a handful of requests - these haven't been created).
I can't find anything in the logs to say there was a problem. To be honest the only way I know the job triggered is because the next action is 1st November - It's a monthly job that runs on the 1st of each month).
I've checked the script that it runs, and if I execute it manually it works, so I know there isn't a problem with the script. It's just the condition that doesn't appear to be working.
Is there anyone that might have an inkling as to what might be wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2024 10:01 AM
Hello @Ramz ,
I am looking for days to exclude as weekends? you have any idea on that.
Thanks,
Sushama K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2024 10:22 AM
I tried getting the Condition logic to work, I used:
(function() {
var cd = new Date();
var cm = cd.getMonth();
gs.info('Condition for Test Job date = ' + cd + ', month = ' + cm);
if ((cm == 0) || (cm == 3) || (cm == 6) || (cm == 9)) {
gs.info("Condition returning true");
return true;
}
else {
gs.info("Condition returning false");
return false;
}
})();
I reviewed other OOB scheduled jobs where conditional = true to see what script syntax was used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2024 11:53 PM
Since people are asking this is what I ended up with:
var gdt = new GlideDateTime();
var month = gdt.getMonthLocalTime();
result = (month == 3 || month == 9 );
result;
(The months to trigger changed).
Despite my previous comments about sandbox and glide functions, the above works. And takes into account daylight saving time.