
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-24-2021 01:33 PM
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
- 752 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
One issue that will likely be rare is that cmnSchedSpan.getDisplayValue('start_date_time') will sometimes return a problematic value if the Run as user's profile has a Time format other than either System or a 24-hour format.
This can be solved in the script by getting the internal display value using GlideDateTime's getDisplayValueInternal, but I'm not sure how to get the internal display value mainly because A) this field is defined as a ScheduleDateTime rather than a GlideDateTime field and B) I'm not sure how to convert it over.
If anyone knows how, please comment with the details. Thanks!