
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
03-22-2021 12:11 AM - edited 08-15-2024 06:38 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Working on Instance Scan, looking at the scripting part, and wondering how to use it? I can imagine 🙂 Like I mentioned in my previous articles, so far the official documentation on Instance Scan is really limited. You can have a look at the out-of-the-box Instance Scan Scan Checks to get an idea. Though… those out-of-the-box Scan Checks all don't use the engine object?! They use finding, current, and columnValue. This is due to the Scan Checks which were created in the Paris release. With the Quebec release though, object engine has been introduced as a replacement.
A short article on how to use the script field and especially the engine object for Scan Check types "Table Check", "Column Type Check", and "Script Only Check". I'll skip Scan Check type "Linter Check" for now, have to dig into this more myself.
finding, current, columnValue
With Scan Check type the Table Check, you've got the option to use the condition builder and/or the script field. When scripting, you will have finding and current as objects. Current being a GlideRecord object, and finding which you would use when actually creating a finding using:
finding.increment();
With Scan Check type Column Type Check you will have finding and columnValue as object. columnValue holds the complete contents of the Script field, XML field, or HTML field, and finding which you would use when actually creating a finding using:
finding.increment();
With Scan Check Script Only Check you will have finding as object. finding which you would use when actually creating a finding using:
finding.setCurrentSource(gr);
finding.increment();
* gr = GlideRecord object which you queried.
engine
As mentioned, with the Quebec release object engine has been introduced. So how does this work? What can we do with it? To start, I hope we can do way more than I'm describing now… though it's just undocumented, no one else shared anything yet. If we look at the above, using objects finding, current, columnValue, applying engine is actually really simple… you would only prefix the code mentioned earlier with engine., that's it!
engine.finding.increment();
engine.columnValue
engine.finding.setCurrentSource(gr);
engine.finding.increment();
Just a random example Scan Check using the engine object:
(function (engine) {
// Define variables
var regex = /\blocalStorage\.(setItem|getItem)\s*\(/g;
// Create scan finding
if(engine.columnValue && engine.columnValue.match(regex)) {
engine.finding.increment();
}
})(engine);
Caution
In the Quebec release you can still use the old method, which you also see in the out-of-the-box Scan Checks. So you don't have to change all your Scan Checks while upgrading. Though be aware… the engine object does not work in the Orlando release and the Paris release!
---
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
---
- 3,024 Views