Scheduled Job always running despite conditional check?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 09:18 AM
Hi,
I have a report that I only want to run on the second Tuesday of each month. I have created a conditional script to check, and it returns the correct results when I run it in a background script. However when I setup the conditional script in the scheduled job it always runs even when my checkCondition() function only has return false options. Any ideas what is happening here?
//script should run only on 2nd tuesday of the month
checkCondition();
function checkCondition(){
var gdt = new GlideDateTime();
//if day of the month is between 8-14 and its the 2nd day of the week (Tuesday), run this script
if((gdt.getDayOfMonthLocalTime() >= 8 && gdt.getDayOfMonthLocalTime() <= 14) && (gdt.getDayOfWeekLocalTime() == 2)) {
//if((gdt.getDayOfMonthUTC() >= 8 && gdt.getDayOfMonthUTC() <= 14) && gdt.getDayOfWeekUTC() == 2){ //check if LocalTime vs UTC effects issue
//return true;
return false;
}
else{
return false;
}
}
(I removed the email addresses for the screen shot)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 10:56 AM
Hello Jared,
Weirdly the condition script is not even evaluating for the scheduled report, I added log statement there and it is not coming up in logs table. I would suggest opening case with ServiceNow HI team.
Meanwhile as a workaround, you can set the when to run as on demand for scheduled report. Then create scheduled script execution with the same condition. in the script to run, you can trigger the scheduled report using the script:
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 11:01 AM
Yeah, I couldn't get anything to log either. Glad to see this isn't just happening to me though. I will open a case with HI. Thank you for your help and suggestion on this!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 11:23 AM
Glad to be helpful. Please let me also know of ServiceNow's reply on case. Thank you.
Thank you,
Ali