GlideRecord.get() and GlideRecord.addQuery() to get records.

ggg
Giga Guru
Scoped GlideRecord - addQuery(String name, Object value)  The first parameter is the table
field name.
Scoped GlideRecord - get(Object name, Object value)The first parameter is the Name of the
instantiated GlideRecord column to search for the specified value parameter. 
When I need to process records in a table I always use addQuery() to filter.
Is this Best Practice?
when should i use the get() method?
1 ACCEPTED SOLUTION

Yes you can use two parameters in the get method i.e get('sys_id', gs.getUserID()) but the get method will only return one record so if your result set will have more than one record user addQuery otherwise if you only need one record returned you can use get().

 

As I stated in my previous response use get() method when you only need a single record returned. That is when it would be the preferable method.

 

View solution in original post

6 REPLIES 6

Not it is not quicker. It is slower.

Internally the get method does not use setLimit(1) and returns all matching records.

So it is much faster to use query with setLimit instead of get.

Omender Singh
Tera Guru

[video]