
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
03-06-2022 10:30 PM - edited 08-03-2024 07:10 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Scheduling a scan with Instance Scan seems very easy, though what if you want to schedule a scan using scripting? For example because it's a daily scan to be run on weekdays or even better workdays? Up to the Rome release, this was not possible. Although the Scheduled Scan tabel [sysauto_scan] contains a script field that you could use... in reality the script field was not be applied at all. After raising a Support Case, ServiceNow confirmed this bug and has come up with a fix in the San Diego release.
Scheduled Scan
When wanting to schedule an Instance Scan scan, one of the methods could be:
- Open a "Suite" record [scan_suite];
- Select the "Schedule" related list and select the "New" UI Action;
- In the modal presented, select the targets for the scan;
- A new scheduled Scan record will be opened which you can complete and save.
Pretty easy!
Run daily... run weekdays
On Scheduled Jobs, there's a field "Run" available. This field contains amongst others the value for "Daily". Basically the Scheduled Job would run daily, on the "Time" set. Unfortunately there's no option to select a Schedule or something similar, which would allow the Scheduled Job only to run on certain Weekdays, or honor a Holiday Schedule. A way to go for this, is utilizing the "Condition" field, which gets visible after checking the "Conditional" field. For Scheduled Jobs this works very well, the script just needs to evaluate to true to be run. Although the Scheduled Scan table is extended from the Scheduled Job table, the Condition field actually did not work up to the Rome release on the Scheduled Scan table. As mentioned, this is a bug that has been confirmed by ServiceNow. With the San Diego release though... the bug is fixed 🙂
Condition
Below example script which you could use to validate if the current day is within a Schedule. For this I do use a Schedule that has a Schedule Entry for "Weekdays" and "All day" checked, plus a Child Schedule that contains all Holidays.
Example script:
(function() {
var schedule_sysid = gs.getProperty('schedule.workdays_exclude_holidays'),
answer = false;
if(new GlideSchedule(schedule_sysid).isInSchedule(new GlideDateTime())) {
answer = true;
}
return answer;
})();
And that's it! After applying this script, the daily Scheduled Scan will only run on days that match the Schedule concerned. Note that in the example above, I am using a System Property "schedule.workdays_exclude_holidays". This System Property contains the Sys ID of the Schedule concerned.
---
And that's it. Hope you like it. If any questions or remarks, let me know!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Platform Architect @ Eraneous
3x ServiceNow Developer MVP
3x ServiceNow Community MVP
---
- 1,648 Views