- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 07:00 PM
Hi,
I am new to instance scan in ServiceNow, I am trying to create a custom scan check for the client script. I want it to check the update set, if there is a on-change client script, it should have isLoading being used as part of the script
For example, it should contain, "if (isLoading)" or if(isLoading || newValue)"
Will this be a linter check or script check ? (regex knowledge needed ?)
Any suggestion would be helpful on this
Please advise
Harsha Pappala
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 04:09 AM
I just did a basic test with only:
(isLoading)
Works, also checks if this is commented or not.
Table Check
Table: Catalog Client Script:
Condition:
Script:
(function (engine) {
// Remove code comments
var commentsRegEx = /\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm;
var commentsRemovedValue = engine.script.replace(commentsRegEx, '');
var search_regex = /\(isLoading\)/;
// Create scan finding
if(!search_regex.test(commentsRemovedValue)) {
engine.finding.increment();
}
})(engine);
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 10:02 PM
Hi there,
Linter Check would be nice, though unfortunately you don't have an option to only check for 1 table. Linter Check will check all script fields.
So you would be better of using a Table Check, and check on the Catalog Client Script table. With Table Check you also have the option to use conditions, so you could already check scripting contains isLoading etc..
It won't be rock solid though, since isLoading might be commented. If you also want that, than you do need to script and apply regex.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 04:09 AM
I just did a basic test with only:
(isLoading)
Works, also checks if this is commented or not.
Table Check
Table: Catalog Client Script:
Condition:
Script:
(function (engine) {
// Remove code comments
var commentsRegEx = /\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm;
var commentsRemovedValue = engine.script.replace(commentsRegEx, '');
var search_regex = /\(isLoading\)/;
// Create scan finding
if(!search_regex.test(commentsRemovedValue)) {
engine.finding.increment();
}
})(engine);
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 03:35 AM
@Mark Roethof Thank you so much for this information Mark 🙂