PA Daily Jobs: Script for Skipping Weekends & Holidays
Hello,
Here is a script that can be added to Daily PA Data Collector Jobs (not historic jobs). This script will make the daily job only collect scores for days that are within the schedule specified in the script. This allows us to not only skip weekends, but to also skip holidays.
To use this script, simply set the following:
- Run: Daily
- Conditional: [Checked] (this makes the Condition field appear)
- Condition: [paste the below script]
Script:
answer = function honorSchedule(){
var cmnSchedSpan = new GlideRecord('cmn_schedule_span');
if (cmnSchedSpan.get('schedule.name','8-5 weekdays excluding holidays')) { //update this to any schedule of your choosing
var scoreStart = new GlideDateTime();
scoreStart.addDaysLocalTime(-1); //mimics today's (yesterday's) collection period
scoreStart.setDisplayValueInternal(scoreStart.getDisplayValue().split(' ')[0] + ' ' + cmnSchedSpan.getDisplayValue('start_date_time').split(' ')[1]);
var sched = new GlideSchedule(cmnSchedSpan.schedule);
if (sched.isInSchedule(scoreStart))
return true;
}
return false;
}();
I saw mention of using a conditional script in this manner in other articles, such as this one, but I didn't see a script provided plus I wanted to add the ability to integrate your chosen schedule. Please advise on any issues with or improvements to this script. Thanks!
Side note: This script should also be compatible with being used elsewhere, such as in the condition of a scheduled report, to make it only be distributed on workdays.
I hope someone finds this helpful.
Kind Regards,
Joseph
https://www.servicenow.com/community/platform-analytics-articles/pa-daily-jobs-script-for-skipping-weekends-holidays/ta-p/2304542