Scheduled Job always running despite conditional check?

Jared Wason
Tera Guru

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)

JaredWason_0-1680711467264.png

 

7 REPLIES 7

Ahmmed Ali
Mega Sage

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;
}
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

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; 
} 

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

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.

 

JaredWason_0-1680715902205.png