Scheduled Report's Condition script is not working properly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 03:13 AM
Hi,
I need my report to run only on weekdays. For this I am using the below script. The issue is, it has run even on Saturday, and didn't trigger on Sunday and Monday.
Whatever the number my instance is updating for the day, the below condition gets satisfied right?
For the below number combination:
0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
As I have given dayOfweek > 0, it should skip Sunday and for dayOfWeek<6 it should skip Saturday.
If we consider below number combination also, the above condition will get satisfied right. I am not getting what the issue is.
1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday, 7= Sunday
var now = new Date();
dayOfWeek = now.getDay();
if (dayOfWeek > 0 && dayOfWeek < 6) {
answer = true;
}
else {
answer = false;
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 04:50 AM
Hi
Could you please help on this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 05:07 AM
Hi,
update as this
var answer = false;
//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();
//Run only on weekdays
if(now.getDayOfWeek() < 6){
answer = true;
}
answer;
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
03-29-2022 05:16 AM
Hi
Thank you. But GlideDateTime() is not working on scheduled reports, so using new Date().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 06:47 AM
Hi,
okay got it
try this and add logs as well
var nowDate = new Date();
dayOfWeek = nowDate.getDay();
dayOfWeek = parseInt(dayOfWeek);
if (dayOfWeek > 0 && dayOfWeek < 6) {
answer = true;
}
else {
answer = false;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader