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

Thanks @Tony Chatfield ,

I think it has to do with Brian's comment about the "Time" field. When testing in an earlier version instance, both of our scripts work and logs are generated. In my Orlando, nothing comes up in the logs.

I think I will open a HI incident.

I'll update.

Thanks,

harel

Also I'm doing a return because I have var answer = ifScript();.  So answer will evaluate to true / false.

I tried with both answer = ifscript(); and ifscript; and I think they both work fine.

I opened a case with HI because they work fine in London, but the exact same script does not run as expected in Orlando. For example: no logs are written and the emails keep getting created and sent, even outside of the designated hours.

I thought it might have to do with Orlando being patch 0, so I updated to patch 1, but still the same. Waiting for HI to get back to me on this one.

find_real_file.png

harel

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

AJIT17
Kilo Contributor

Hi, I have tried above script on orlando version but it doesn't work for me with slight change in code 

//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() < 5 && hours >= 10 && hours <= 20) {
answer = true;
}
gs.log('hbs --> now ' + now.getDay() + ' time ' + hours + ' answer ' + answer);
answer;

I wanted the report to run 10 AM to 06 PM IST. Kindly suggest any change is required in code.