how to run strict query for gliderecord.

sumitjumale
Kilo Contributor

Hi All,

I have requirement to   get all the records based on the query from the script. Suppose if we use the fields names which are not present in the table, then it should not return any records, But servicenow returning all the records in the table.

Example : status filed is not present on table "TABLE_ABC" . if we query with encodedQuery as "status=true" then its returning all the records present in that table.

So I need servicenow should not return any records if the encoded query is incorrect.

Sample Code:

var ref_rec = new GlideRecord('TABLE_ABC');

ref_rec.addEncodedQuery('invalidquery');

ref_rec.query();

while(ref_rec.next()){

gs.print(ref_rec.getRowCount());

  }

Output:

Its returning total row count as 5000

but since query is invalid, it should not return any records.

Please help me to resolve this issue.

Regards,

Sumit Jumale

9 REPLIES 9

It's supposed to be a non-existing field name within table Incident. i.e. u_abc_xyz_123. No matter what its name is, the result is still the same.


Interesting, I just took your script, set the property to true and ran it on my Helsinki P4 instance and got this:



*** Script: glide.invalid_query.returns_no_rows=true


field name 'non_exist_id' not found in table 'incident'


*** Script: Encoded query=[sys_idNotValidnull]


*** Script: 0



Based on this, it would appear that gs.getSession().setStrictQuery(true); is not working. I'll check with the development team and let you know what I find out.


I simply use like this with invalid field 'sensitivity':



gs.getSession().setStrictQuery(true);


var gr = new GlideRecord('incident');


gr.addQuery('sensitivity' , 1);


gr.query();


gr.next()


gs.print(gr.getRowCount());



getting all records in the output , gs.getSession().setStrictQuery(true)   seems useless.


Any suggestions or alternate way to make it work?


I know it used to work in previous releases. Let me check with the developers on this one...


Hi Chuck,



Kindly update if you get any info for gs.getSession().setStrictQuery(true) method which seems to be not working as per the thread