- 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 09:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 09:58 PM
You can use below script to check your Catalog Client On-Change Scripts :
var isLoadingIncludedScripts = [];
var isLoadingNotIncludedScripts = [];
var gr = new GlideRecord('sys_update_set');
// Replace with sys_id of your update set
gr.addQuery('sys_id','babd70162ffe35d02b86d4a72799b67a');
gr.query();
if(gr.next()){
var gx = new GlideRecord('sys_update_xml');
gx.addQuery('update_set',gr.sys_id);
gx.addQuery('type','Catalog Client Scripts');
gx.query();
while(gx.next()){
if((gx.payload).indexOf('function onChange') != -1){
// Check for is Loading
var regex = '\\(isLoading';
if((gx.payload).match(regex)){
isLoadingIncludedScripts.push(gx.target_name.toString());
}
else{
isLoadingNotIncludedScripts.push(gx.target_name.toString());
}
}
}
gs.print('Catalog Client Scripts Which has isLoading function included are : '+isLoadingIncludedScripts );
gs.print('Catalog Client Scripts Which does not have isLoading function included are : '+isLoadingNotIncludedScripts );
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 10:02 PM
That's not a Scan Check?
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:12 PM
This is just a standalone utility to check a particular update set for isLoading function in On-Change Catalog Client Script, not a scan check. I use it for my internal audit purposes.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.