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

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:

SncTriggerSynchronizer.executeNow(GlideRecord_Object_of_scheduled_report_to_run);
 
The above statement is taken from OOTB "Execute now" button on scheduled reports table. 
 
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

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!

Glad to be helpful. Please let me also know of ServiceNow's reply on case. Thank you.

 

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

Thank you,
Ali