how to run strict query for gliderecord.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 03:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2016 06:42 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2016 05:51 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 12:04 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 06:39 AM
I know it used to work in previous releases. Let me check with the developers on this one...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2017 03:02 AM
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