logo

NJP

Rudimentary Things to Remember – Topic 1

Import · Feb 28, 2022 · article

***Most of the readers might be aware of this topic, however sharing it as it is a critical issue for the folks who are not aware of this topic***

Have you ever run a query and you think is good enough but ultimately it affects the database badly? If so, go through this article which helps you to avoid this mistake next time.

Scenario : Count number of incidents which are created after certain date.

Expected Result : 2

Original Result : 134

Code :

var agg = new GlideAggregate('incident');
agg.adddEncodedQuery("sys_created_on>javascript:gs.dateGenerate('2022-02-27','20:59:59')");
agg.addAggregate('COUNT');
agg.query();
agg.next();
gs.print(agg.getAggregate('COUNT'));

Output

*** Script: 134

Reason : If we provide any query in incorrect format in such scenarios the invalid part of the query will get ignored and executes the remaining part, so same thing was happened in the above scenario where instead of “addEncodedQuery” I have used “adddEncodedQuery”(Extra ‘d’ letter in it), due to this that line got ignored and it executed the remaining part which results in total count of incidents.

How can we override it : We can handle it by using this system property glide.invalid_query.returns_no_rows. When this property is true, invalid queries always return no rows.

Steps to create system property:

  1. Navigate to /sys_properties_list.do
  2. Click on New and fill with the below parameters:
  3. * Name: glide.invalid_query.returns_no_rows
    • Type: true | false
  4. Value: true

Thanks for reading the blog and do provide your inputs/suggestions if any.

Hope you find this article helpful. Don’t forget to Mark it Helpful / Bookmark.

Thanks,
Raghu Ram.

View original source

https://www.servicenow.com/community/itsm-articles/rudimentary-things-to-remember-topic-1/ta-p/2300448