63 views

Description

Multiple messages in the log table or system logs containing the following or similar message:

Invalid query detected, please check logs for details [Unknown field undefined in table sc_request]

Release or Environment

Any

Cause

This error is produced by a business rule on the affected table (Usually that table is part of the error message IE: sc_request). 


The business rule will attempt to call the GlideRecord function next() on a GlideRecord object, when that object has no more records to return on the list.


IE: 

 var gr = new GlideRecord('sc_request');
 gr.addQuery('sys_id', current.request);
 gr.query();
 gr.next();  //<----- Problem line



This code should only call a single row, however we attempt to run gr.next(). This will trigger the invalid query error.

Resolution

Be careful when using gr.next() on a GlideRecord object. Usually these are part of a conditional statement such as a while loop or an if otherwise it would be a similar equivalent to an out of bounds error in an array. 


Simply avoid using gr.next() outside of conditional statements if not needed to loop through one or more records. If only returning one record and the unique sys_id is know, please use the gr.get('REPLACE-SYS-ID-HERE') function. 

Additional Information

Review the GlideRecord API for more information

GlideRecord API

Article Information

Last Updated:2020-11-05 11:06:09
Published:2020-11-05