- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 09:21 AM
Hi all, was wondering if it's possible to iterate through a GlideRecord twice. This is just an example I whipped up, wondering if resetting the iterator is possible.
E.G.
var user = new GlideRecord('sys_user');
user.addQuery('user_name','jason');
user.query();
while(user.next()){
//do stuff
}
user.functionToResetIterator(); //is there functionality to do this??
while(user.next()){
//do other stuff
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 09:27 AM
You can do something like this:
var user = new GlideRecord('sys_user');
user.addQuery('user_name','jason');
user.query();
while(user.next()){
function1(user);
function2(user);
}
function1: function(user){
// do function1 stuff
}
function2: function(user){
//do other stuff
}
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 09:24 AM
Hello,
Yes it is possible:-
Please find a below thread related to same.
https://community.servicenow.com/community?id=community_question&sys_id=b6285411db99d890190dfb24399619df
Please mark answer correct/helpful based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 09:57 AM
I read through this yesterday while researching. To me, it's not possible to iterate twice. Your answer says 'yes, it is possible' but I didn't see a solution on how to do this. Am I missing something?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 09:24 AM
Hi,
Instead of reiterating it again you can put logic in same while block.
Or use same GlideRecord query again to get same records.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 09:27 AM
You can do something like this:
var user = new GlideRecord('sys_user');
user.addQuery('user_name','jason');
user.query();
while(user.next()){
function1(user);
function2(user);
}
function1: function(user){
// do function1 stuff
}
function2: function(user){
//do other stuff
}
Thanks,
Anil Lande
Thanks
Anil Lande