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 01:57 AM
Hi
the problem is that it is difficult to change habits once they have been established. ServiceNow's pace of innovation is so fast that there is hardly any time to try out improved APIs and patterns and introduce them into current projects. Most developers then prefer to stick with what they already know and are reluctant to change.
On the Developer Blog you can find an article series about GlideQuery (https://developer.servicenow.com/blog.do?p=/tags/glidequery/) so you can be sure, that ServiceNow itself would like to see more code with GlideQuery instead of GlideRecord.
Kind regards
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 08:06 AM
I agree 100%:
"...ServiceNow's pace of innovation is so fast that there is hardly any time to try out improved APIs and patterns and introduce them into current projects. Most developers then prefer to stick with what they already know and are reluctant to change."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 02:49 AM
Hi Bruno,
Just my personal opinion.
I'm just waiting for somebody else to confirm it's stable and usable in production. It operates on a database table and if there is a problem, it may affect many records.
GlideQuery still does not support all encoded queries avaible to GlideRecord. Not sure if I can use GlideFunction in the query.
This method does not support all GlideRecord encoded query operators.
According to the following page, it's little slower than GlideRecords. When processing many records, not sure how that would affect performance. Also haven't see performance comparision between GlideAggegregate and GlideQuery.
https://www.streyda.eu/post/gliderecordorglidequery
I, also, haven't seen any comparison on memory usage.
Flow Designer allowed non-programmers to create flows easily. That was a big advantage.
Teaching non-programming to write script seems easier with GlideRecord because the pattern is more in line with introductory programming tutorials. That is, it's easier to teach writing and debugging when there is 1 line per operation. It would be more difficult to debug a line in GlideQuery.
GlideQuery still requires writing codes. Comparing advantage and risk, it's still seems safer to be using GlideRecord.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2022 03:06 AM
For example, which script is easier to debug. (Both script don't work as expected.)
It's not good practice to nest GlideQuery but some questions do contain nested queries.
GlideQuery
var gq = new GlideQuery('sys_user')
.where('manager.user_name', 'abel.tuter')
.select('user_name')
.forEach(function (sys_user) {
var gqLoc = new GlideQuery('cmn_location')
.where('sys_id', sys_user.location)
.select('name')
.forEach(function (location) {
gs.info(location.name);
});
});
GlideRecord
var gr = new GlideRecord('sys_user');
gr.addQuery('manager.user_name', 'abel.tuter');
gr.query();
while (gr.next()) {
var grLocation = new GlideRecord('cmn_location');
grLocation.addQuery('sys_id', gr.location);
grLocation.query();
if (grLocation.next()) {
gs.info(grLocation.name);
}
}