What about GlideQuery ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 12:43 AM
Hi,
Does anyone use GlideQuery instead of GlideRecord?
This object seems very attractive to me, is very well documented on docs.snow.
Its source code is readable.
But I can't find much about it on the community...
What do you think ?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 06:39 AM
The query below:
new GlideQuery('sys_user')
.where('manager.user_name', 'jess.assad')
.select('user_name', 'manager.name', 'manager.location.name')
.toArray(10);
will return the results below:
[
{
"user_name": "krystle.stika",
"manager": {
"name": "Jess Assad",
"location": {
"name": "2-10-1 Yurakucho, Chiyoda-ku, Tokyo"
}
},
"sys_id": "02826bf03710200044e0bfc8bcbe5d7f"
},
{
"user_name": "naomi.greenly",
"manager": {
"name": "Jess Assad",
"location": {
"name": "2-10-1 Yurakucho, Chiyoda-ku, Tokyo"
}
},
"sys_id": "0382abf03710200044e0bfc8bcbe5d42"
}
]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:12 PM - edited 10-04-2023 10:15 PM
Your first example will not work because you select 'user_name' but then attempt to use 'location'. Plus it is very inefficient as you could have just dot-walked to the location name without the extra query. Plus not much point assigning it to a variable.
new GlideQuery("sys_user")
.where("manager.user_name", "abel.tuter")
.select("location.name")
.forEach(function (user) {
gs.info(user.location.name);
});
Second example only needs to be like this
var gr = new GlideRecord("sys_user");
gr.addQuery("manager.user_name", "abel.tuter");
gr.query();
while (gr.next()) {
gs.info(gr.location.name);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 06:28 AM
ServiceNow internal developers are using GlideQuery in the platform development, so I would say it's stable and production-ready.
Adding encoded query support is in the works... I thought it was added in Rome, but cannot find any docs to support that.
GlideQuery is a wrapper for GlideRecord AND GlideAggregate so there is some translation and added overhead.
- Speed is not the reason for GlideQuery, but it should also not be a reason to avoid it. The difference should be small if you define your query effectively.
- Memory usage should be similar as it is only a wrapper for what you are already using.
- GlideQuery is a safer option that will raise errors rather than blindly attempting a database action with a bad filter... potentially corrupting data.
- GlideQuery results are reusable so you do not need to re-query the database... making this a faster option in circumstances where it applies.
- GlideQuery produces results that are native JSON data, making them easier to use and easier for developers new to ServiceNow to learn.
The whole no/low-code push has its place, but there are some skills that come with learning to code that are missed. The ability to articulate a process into clear, discreet requirements is derived from IT and people who think they can jump into ServiceNow without that skill are going to struggle. I suspect this means the developers will spend more time cleaning up and coaching non-developers over time. I could be wrong and would be interested in feedback from teams that have had citizen non-developers for some time.
Good luck!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 08:04 AM
Where I would exercise caution is inside your organization. Will the rest of your team be able to support the solutions you create with GlideQuery? Do you have the option of providing lunch-and-learn style sessions to explain GlideQuery and get feedback about the team's willingness to learn and adopt it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2022 12:27 AM
Hi All,
Thank's a lot for your interesting answers.
what I understand is that it is promising but be careful all the same.
I think I will invest some time on this object with all the recommendations you mention.
This code is still young it will probably evolve, especially if OOTB starts using it.
Once again thank you.