Create custom instance scan check for isLoading on client script

Harsha Pappala
Kilo Sage

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

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

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:

MarkRoethof_0-1704456553416.png

 

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

LinkedIn

View solution in original post

7 REPLIES 7

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

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:

MarkRoethof_0-1704456553416.png

 

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

LinkedIn

@Mark Roethof Thank you so much for this information Mark 🙂