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 09:35 AM
can you try
//script should run only on 2nd tuesday of the month
checkCondition();
function checkCondition(){
var answer = false;
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;
answer = true;
}
return answer;
}
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 09:58 AM
Hi Ahmmed,
I tried your version and it still runs despite not being the 2nd Tuesday of the month. Even this simple script that always return false is still running.
//script should run only on 2nd tuesday of the month
checkCondition();
function checkCondition(){
var answer = false;
return answer;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 10:05 AM
Hi @Jared Wason
Can you try once below script and check if works.
(function() {
return false;
})();
Also how are you testing it? clicking on the execute now button? or updating the when to run such that it will run automatically in sometime?
If you are clicking on the execute now button, I think it will bypass condition and run the script always. You can test it by updating when to run as run once and give data and time 5 mins from now and wait for it to run.
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2023 10:32 AM
The report is still getting triggered even with the above script. I am testing by updating the when to run field by a couple of minutes.