
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
03-14-2021 11:01 PM - edited 08-15-2024 06:38 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
So you've touched on Instance Scan, maybe read my previous blogs on Instance Scan, or saw Live Coding Happy Hour of last Friday on Instance Scan. And now, wanting to automate scan checks. Are there any possibilities for this? Obviously you could schedule scans, though what about tying scans to Automated Test Framework, a Flow, or a Business Rule.
There are scripted possibilities 😀. Documenting the undocumented!
Executing scans through script
Digging around a bit I noticed these two lines of code:
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerFullScan();
After executing these two lines of code, a scan would be started for a full Instance scan. That looks interesting and seeing such code I immediately wonder if there might be more. Unfortunately, we can't read sn_instance_scan. Though performing a code search, Script Include "ScanAjaxProcessor" shows some more scan.trigger* functions. I've listed them below:
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerSuiteScan(suiteId);
(executes a full Instance scan)
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerAppScan(scopeId);
(executes a Application scan)
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerUpdateSetScan(updatesetId);
(executes a Update Set scan)
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerScanFromCombo(comboId);
(executes a scan according to the source and target of the Combo record)
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerPointScan(tableName, sysId);
(executes a scan on a certain Process record)
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerTestScan(scancheckId);
(executes test scan on a scan check)
Tested them all, and all work fine, and immediately start a scan. Only the scan.triggerScanFromCombo() and scan.triggerPointScan() could cause some confusion.
The scan.triggerScanFromCombo() need a sys_id of an existing scan_combo record, while scan.triggerPointScan() needs to be run against a Process record that has available checks applicable to the record, the user has read access to the record, the record is on a table that extends sys_metadata, and the role of the user must be scan_user.
After searching a bit more, I noticed a function to get a combo record or to create a combo record if the combination for the source and targert does not exist yet.
new sn_instance_scan.ScanUtil().getOrCreateComboFromSuiteAndTargets(suiteId, targetTable, targetIds);
Usage could be something like:
var comboId = new sn_instance_scan.ScanUtil().getOrCreateComboFromSuiteAndTargets('', 'sys_ui_action', ['1218f7b3cb100200d71cb9c0c24c9cdf']);
var scan = new sn_instance_scan.ScanInstance();
var result = scan.triggerScanFromCombo(comboId);
Automating
Knowing the above opens a lot of possibilities for automating scans (other than scheduling). An example could be having an after or async Business Rule responding to a certain logic, like Automated Test Framework being executed or changing the state of a Story to Testing. Just adding these few lines of code to the script of the Business Rule (or through a Flow and using an Action), would automate your scan! It's just a simple example of what you could do. I'm sure some of you will come up with some really interesting cases for automated scans.
---
And that's 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 @ Quint Technology
2x ServiceNow Developer MVP
2x ServiceNow Community MVP
---
- 2,988 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
HI, Is there any way, update set scan can validate script level check?
As of now, update set scan can only validate "table" and "column" level check. This is very much limitation to use this functionality while automation update set scan during our development cycle.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@sailee My recommendation would be to NOT use update sets for deployments anymore. It's 2022 - time to move to source control backed deployments. One of my clients (180 developers on one instance alone, with 150+ scoped and global apps) was struggling here as well. They move to source control and deployments are so much easier now. And by doing so, they scan apps (instead of update sets) and are on a good way to fully automate the pipeline process (including running Instance Scan checks and ATF tests). It's awesome how much more productive a team can be.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In case someone wonders how this is possible....
Check this out:
https://www.wildgrube.com/download/A%20mature%20Development%20and%20Deployment%20Process.pdf
Enjoy reading and spread the word!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Good that one of the Knowledge keynotes it was mentioned that more than 95% is still using update sets 😋

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Mark Roethof you mean it was good that it was mentioned? Or it is good that still so many use update sets?????

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes its good that it was mentioned, since that is the reality we are living in and it won't change that quickly any time soon 😅.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
That's all on us! It's in our hands to guide and consult our clients towards building apps-only and integrate source control. The platform will see some features in upcoming releases that are game-changing. But the existence of tools doesn't make the change alone. I advise clients to start their journey today - every day. I call out to all consultants out there to nudge their clients in that direction, too! 😄