Get array field of glideRecord object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 05:18 AM
Hi,
I was wondering if there was an optimised way of retrieving all field values of a queried glideRecord.
The naive way is iterating through each glideElement and push the field (sys_id for example) to an array. I feel like there should be an optimisation that doesn't require me to iterate with the next function.
Any input ?
Thanks in advance
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 05:32 AM
Hi,
it would be nice if you share some context with example and script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 05:56 AM
Hi,
this would be the kind of script i want to optimize :
var arr = [];
var gr = new GlideRecord("sys_user");
while (gr.next){
arr.push(gr.department);//or some other field
}
I know what field values i want, i feel like there should be an optimized/bulk way of retrieving that. Rn this take 20s approx, way too long for my needs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 06:01 AM
There should be just a handful of departments, why don't you just extract them from cmn_department table?
If you loop over the user table then you will get many duplicates and may have to resolve that too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 06:34 AM
Because i don't need a full department list, i need every department that is linked to a user. I will run a uniqueArray on the result for what it's worth, but it is quicker to go from user table than to check every related list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 05:41 AM
You can use GlideQuery's select method to get one or more fields from the list of queried records. More details here.