- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2020 06:55 AM
Good morning community,
I am seeing something strange on some scheduled reports using conditional scripts to determine which days to run (weekdays and fridays being the important ones). I did the searching and saw the notice about using js and not glidedate, and even copied the supplied script. It works on a couple of my scheduled reports, but not on others. Can you see why as I am stumped! If I remove the conditional script check box, these send fine. With conditional, they will not send when clicking EXECUTE NOW or on the schedule.
This one does NOT work-
// This condition should cause the scheduled report to only run on a weekday (Mon - Fri)
// 0=Monday,1=Tuesday,2=Wednesday,3=Thursday,4=Friday,5=Saturday,6=Sunday
var d = new Date();
dayOfWeek = d.getDay();
if(dayOfWeek < 5) {
answer = true;
}
else {
answer = false;
}
This one DOES work-
// This condition should cause the scheduled report to only run on a weekday (Mon - Fri)
// 0=Monday,1=Tuesday,2=Wednesday,3=Thursday,4=Friday,5=Saturday,6=Sunday
var d = new Date();
dayOfWeek = d.getDay();
if(dayOfWeek < 5) {
answer = true;
}
else {
answer = false;
}
Since these are the same, I am not sure why the top one does not run at 7 AM, but the bottom one does run at 3 PM?
Clicking EXECUTE NOW does not send these reports, unless I remove the conditional checkbox, and they then sent. What can be causing this?
Thanks!
Jeff
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2020 07:30 AM
I'm not sure of the exact cause. You can make a try. Normally week starts with Sunday so your condition should be like below:
// This condition should cause the scheduled report to only run on a weekday (Mon - Fri)
// 0=Sunday,1=Monday,2=Tuesday,3=Wednesday,4=Thursday,5=Friday,6=Saturday
var d = new Date();
dayOfWeek = d.getDay();
if(dayOfWeek >= 1 && dayOfWeek <= 5) {
answer = true;
}
else {
answer = false;
}
Also make sure active flag is checked.
Thank you,
Palani
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2020 07:30 AM
I'm not sure of the exact cause. You can make a try. Normally week starts with Sunday so your condition should be like below:
// This condition should cause the scheduled report to only run on a weekday (Mon - Fri)
// 0=Sunday,1=Monday,2=Tuesday,3=Wednesday,4=Thursday,5=Friday,6=Saturday
var d = new Date();
dayOfWeek = d.getDay();
if(dayOfWeek >= 1 && dayOfWeek <= 5) {
answer = true;
}
else {
answer = false;
}
Also make sure active flag is checked.
Thank you,
Palani
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2020 07:40 AM
You are correct I think. I have been troubleshooting it, and I think I was led astray by the Hi article I found the above script in. I found a previous day checker in use and their days have 0 as Sunday as well, not Monday like I have in this new one. And given the times I was testing this, I think is the other part that made this APPEAR to work for the one report.
Confirming it now, but so far it is checking out. Thanks for the tip!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2020 07:39 AM
Hi,
Please check this issue might be because of timezone of the user you have given in the Run as field of your scheduled report.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2020 07:46 AM
Oddly, I have found that the timezone fields, either of the two, have zero effect if set or not set. Even if I set them to run EST, it still runs on my timezone of CST. So long as it is consistent, I don't care about that, but it is strange that it ignores the timezone field and the run as tz field.