Scheduled Report - not working with condition

oharel
Kilo Sage

Hi all,

I would like to send a report every hour between 15:00 and 20:00, every day except for Sunday.

The scheduled report is configured like so:

find_real_file.png

I have the following condition in a scheduled report (based on @Brian Lancaster 's answer here; thanks Brian!)

answer = ifScript();

function ifScript(){
	var d = new GlideDateTime(); //setup date time object
	d.setValue(gs.nowDateTime()); //set to current date/time
	var dt = d.getTime().toString().split(" ")[1];
	
	var time = dt.split(":")[0];   //Gets Hours
	
	//Sunday (7), Monday (1), Tuesday (2), Wednesday (3), Thursday (4), Firday (5), Saturday (6)
	if(d.getDayOfWeekUTC() != 7){ //Don't run on Sunday.
		if(time == "15" || time == "16" || time == "17" || time == "18" || time == "19"){ //run at 15,16,17,18,19
			return true;
		}
		else{
			return false;
		}
	}
}

Still, the report is generated every hour, even before 15:00 and after 20:00.

Not sure why.

(Running the script in a background script shows the correct response...)

Your thoughts are welcome.

harel

1 ACCEPTED SOLUTION

oharel
Kilo Sage

After contacitng Hi, this is the final script that works:

//Sunday (0), Monday (1), Tuesday (2), Wednesday (3), Thursday (4), Friday (5), Saturday (6)

var answer = false;

var now = new Date();
var hours = now.getHours() + 10;
if(now.getDay() != 0 && hours >= 15 && hours <= 20) {
	answer = true;
}
gs.log('hbs --> now ' + now.getDay() + ' time ' + hours + ' answer ' + answer);
answer;

Also, to get the log statement logged: gs.log() is ignored silently in sandbox. You can edit system property "glide.security.sandbox_no_logging" to set it to false to enable logging.

harel

View solution in original post

10 REPLIES 10

Hi Ajit,

Two things you want to check:

1. that the system property glide.security.sandbox_no_logging is set to false. This will allow you to see logs from the scheduled script

2. that the time offset is what you need. For me, at the moment, it shows "1", so I had to add 10 to make it 11. 

After setting the system property to false, you can check by adding the following line as the first line in your script:

gs.log('Ajit --> now getHours ' + new Date().getHours());

This will give you the time, to which you can then add as many hours as you need.

Hope it helps

harel