Scheduled Report Conditional Script Problem

jlaps
Kilo Sage

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

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

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

Thank you,
Palani

View solution in original post

5 REPLIES 5

anaghas
Tera Contributor

As per Servicenow docs, the last line of the condition script should evaluate to true/false. Scheduled Job

Can you modify your script like below and try?

// 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

(function() {

var dayOfWeek = new Date().getDay();

return (dayOfWeek < 5);

})();