Skip navigation

Developer Community

1 Post authored by: Catie Carmody Employee

There is a functionality in GlideRecord such that you can end up querying the entire table instead of a specific subset of records if an invalid query is accidentally passed into GlideRecord query methods. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert(), update(), deleteRecord(), or deleteMultiple() method on bad query results can result in data loss! The good news is that there is a quick and easy way to avoid this. Simply set the glide.invalid_query.returns_no_rows system property to true to return no rows (instead of all rows) when the query is invalid.

 

Use this glide sys property to prevent data loss and other issues with custom scripts

Here is an example of where we can end up in a situation where we return all rows instead of specific ones because we don't validate the query parameter:

var a;
var gr = new GlideRecord("incident");
gr.addQuery("number", a);
gr.addQuery("caller", a)
gr.query();

while(gr.next()) {
     gs.print(gr.number);  //Printing all incident numbers but would expect 0 records back, if this called deleteMultiple() you could delete ALL incidents!
} 

To protect yourself from the above scenario, set the glide.invalid_query.returns_no_rows system property to true.

 

What is the glide.invalid_query.returns_no_rows system property?

The glide.invalid_query.returns_no_rows system property controls how invalid GlideRecord queries are handled. When this property is true, invalid queries always return no rows. When this property is false (default), if a query is incorrect, such as by including an invalid field name, the invalid part of the query condition is ignored and results are based on the valid part of the query. You can find more information about this sys property, as well as all the sys properties available in the platform, here: Available System Properties

 

How to set this system property

  1. Navigate to <instance_name>.service-now.com/sys_properties_list.do
  2. Create a New sys_properties record with the following parameters set:
    • Name: glide.invalid_query.returns_no_rows
    • Type: true | false
    • Value: true

new system property.png

By setting glide.invalid_query.returns_no_rows to true, you can prevent data loss and other issues with custom scripts.

Filter Blog

By date: By tag: