- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:28 PM
in a script I want to query certain records in table ABC with a Glide Aggregate to get a count of certain records.
Then for any computer with a count > 3, I want to update a record in the asset table.
My code works for the first record with a count > 3 but it never executes the code in the second .next() section a second time. Any insight would be appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:50 PM
Hi,
You'd want to also declare your upAuDit JavaScript variable within the while loop OR...reset it with upAuDit.initialize() each iteration.
Otherwise it's all associated to the first pass.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:50 PM
As a general rule, nesting queries will cause you more issues than not, especially in the area of performance. It is usually a better idea to run your first query, iterate through the results, and push whatever data you need to make your second query to an array and then at the end call you second query and iterate.
That being said, your second query only operates once because you initialize it outside of your first while loop and never reinitialize it - once you have made called .query you can't add a query to the same object and call .query again.
Inside your if(myCount>3) statement, include a line like this before you call addQuery()
upAudit = new GlideRecord('alm_asset');
This way during each iteration you "refresh" your variable, add your query and then call your query.
That will at least give you the results you're looking for but - again - I'd suggest you push that you need to an array and turn this into separate queries rather than nesting them in this way.
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 02:50 PM
Hi,
You'd want to also declare your upAuDit JavaScript variable within the while loop OR...reset it with upAuDit.initialize() each iteration.
Otherwise it's all associated to the first pass.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 03:07 PM
Thank you both. The movement of the upAuDit JavaScript variable within the while loop solved the issue for me. I will also look into the use of an array for these purposes.