- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 12:05 PM
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:
I have the following condition in a scheduled report (based on
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 04:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 01:51 AM
Thanks
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 07:32 AM
Also I'm doing a return because I have var answer = ifScript();. So answer will evaluate to true / false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 08:24 AM
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.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 04:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 10:59 PM
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.