Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

VaranAwesomenow
Mega Sage

In order to prevent accidently querying ServiceNow using a malformed encoded query implement following

1. Create a system property glide.invalid_query.returns_no_rows with value as true.

2. Add validation in your scripts to check if encoded query is valid using isValidEncodedQuery()

 

Video :

 

Example script : 

try {
var counter = 0;
var grServer = new GlideRecord('cmdb_ci_server');
var enQuery = 'sys_class_name=cmdb_ci_server'; // class is server
var isValidQuery = grServer.isValidEncodedQuery(enQuery);
if (isValidQuery) {
grServer.addEncodedQuery(enQuery);
//grServer.setLimit(1);
grServer.query();
while (grServer.next()) {
grServer.setValue('short_description', "Iam a server");
grServer.setWorkflow();
//grServer.update();
counter++;
}
} else {
throw "Encoded query is invalid. Please check and update the script";
}
gs.print('Records updated = ' + counter);
}
catch(ex) {
var message = ex + '';
gs.print('caught exception=' + message);
}

 

 

References : https://www.w3schools.com/js/js_errors.asp

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideRecordScope...

 

Version history
Last update:
‎11-14-2022 08:55 PM
Updated by:
Contributors