addEncodedQuery in Lower Case Results Are Strange Instead of Error

Rahul Priyadars
Giga Sage
Giga Sage

Hi All

 

in one my script i used below and results are as expected.

 

var incGr = new GlideRecord('incident');
var cn=0;

incGr.addEncodedQuery('active=true^reassignment_count>2');

 

Now i did this and it is returning all incidents instead of throwing syntax error.

 

var incGr = new GlideRecord('incident');
var cn=0;

incGr.addencodedquery('active=true^reassignment_count>2');

 

why i tested this in some of the env my junior developers used lower case method name resulting into more records fetched and it updated more no of records causing issue.

 

I tested both versions above and behavior with lowercase is really Strange.

 

Am i missing something here . Please put some light on this .

 

Regards

RP

5 REPLIES 5

Astik Thombare
Tera Sage

Hi @Rahul Priyadars ,

 

The reason why the lowercase addencodedquery is fetching all incidents and the uppercase addEncodedQuery works as expected is due to JavaScript's case-sensitivity.

 

JavaScript is Case-Sensitive: Function and method names are case-sensitive in JavaScript. This means addEncodedQuery and addencodedquery are treated as entirely different functions.Missing Function: Since there's no built-in function named addencodedquery in the GlideRecord object, the script silently ignores it and continues execution. This results in no filtering being applied, leading to all incidents being retrieved.

 

      If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Asti

GlideRecord is Service Now Created Class and the Method addEncodedQuery is member of this CLass , Simple OOPS concept. 

 

How come a method is not part of the Class still called and no error / warning issued. 

 

This is severely strange and risky . So same will go for all methods which are part of Gliderecord Class correct.

 

Regards

RP

Hi @Rahul Priyadars,

 

As @Astik Thombare has advised, JavaScript is case sensitive and if a method has a typo (including case sensitivity issues), or simply doesn't exit, SN will silently ignore it.

All other valid queries will be executed. So in your case, all records were passed back from your initialization of the incident table.

 

Whilst on the topic of invalid queries and closely related, a handy system property which is not very well advertised is: glide.invalid_query.returns_no_rows

 

See the Docs: https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/reference-pa...

 

I'd also recomment the man, the myth, the legend @Uncle Rob's video on this when helping the junior Devs (Make sure you see it through and the point on false positives vs false negatives and how to use this and wrap it in a method.

https://www.youtube.com/watch?v=XQxZnRwKcws

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

Hey!  Thanks for the shout out.