- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 08:12 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 08:41 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 08:29 AM
Use get() method when you only need a single record returned and you know the sys_id. It is a bit quicker at retrieving the record from the database.
i.e.
var gr = new GlideRecord('sys_user');
if(gr.get(gs.getUserID())){
//Do something with returned glideRecord
gr.name = 'New Name'
gr.update();
}
vs
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(gr.next()){
//Do Something
gr.name = 'New Name';
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 08:35 AM
that I know ... but you can also use get() with two parameters to get a result set as denoted above.
that is my question, which is preferable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 08:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:25 AM
It is mentioned in the following docs that .get() can be used to retrieve mutiple records from a table.
link: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideRecordScope...
It mentions that "If multiple records are found, use next() to access the additional records."
So, in terms of performance, is get() method faster than addQuery/query when used to retrieve mutiple records?