How to restrict columns retrieved in Glide Query - ServiceNow Community

How to restrict columns retrieved in Glide Query

rohanhd
Kilo Contributor

Hi All, we are all familiar with query using Glide Record. But when we query table for e.g. sys_user we can restrict the number of records retrieved by specifying addQuery conditions.

But this retrieves all the columns within the record. It impacts performance if there are many glide calls. Question is : is there a way to restrict number of columns retrieved in Glide Record.

Is there something I can do to say I only want a certain set of columns.

9 REPLIES 9

Daniel Draes
ServiceNow Employee
ServiceNow Employee

Unfortunately there is no supported method in restricting the columns to be returned from a GlideRecord.



A workaround would be to define a database view and only include the columns you need. However, these views are read only.


For more information on database views see here: Database views


aswinsiddaling2
Kilo Guru

I believe creating an index for the table would be one possibility to fetch only selected columns and reduce performance impact.



Lets see what others have to say for your question.



Thanks and Regards,


Aswin Siddalingam


How do you think an Index would help? As per my experience an index helps to improve speed of searching, but the GlideRecord would still return all columns.



But essentially, if only the performance is an issue for Rohan, than yes, setting an index on the columns of the query condition would certainly help.


Midhun1
Giga Guru

Hi Rohan,



If you query a record it will give you the sys_id of whole record including   both records (rows) and fields (columns).



You can try using gear box and limit the columns.



You can   limit for records using setLimit() this method.