- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2021 03:29 PM
I am using GlideRecord to search through records in a table, but I would like to modify the hasNext() function to tell me when the last record has been reached and there is not a next record.
I tried:
var gr = new GlideRecord("test_table_example");
gr.query()
while(gr.next()){
if(!gr.hasNext()){
gs.info("Last Record Reached");
}
}
This does not work however, any ideas?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2021 03:51 PM
Are you certain this isn't working for you? I've used something similar in the past and seemed to get positive results.
I did a test in a PDI where I have 83 incidents:
var incidents = new GlideRecord('incident')
incidents.query();
gs.info(incidents.getRowCount())
var count = 1
while(incidents.next()) {
if(!incidents.hasNext()) {
gs.info('done at ' + count)
}
count ++
}
And I see this:
*** Script: done at 83
Maybe try logging gr.getRowCount() and a count variable and see what the results are.
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires 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
02-24-2021 03:51 PM
Are you certain this isn't working for you? I've used something similar in the past and seemed to get positive results.
I did a test in a PDI where I have 83 incidents:
var incidents = new GlideRecord('incident')
incidents.query();
gs.info(incidents.getRowCount())
var count = 1
while(incidents.next()) {
if(!incidents.hasNext()) {
gs.info('done at ' + count)
}
count ++
}
And I see this:
*** Script: done at 83
Maybe try logging gr.getRowCount() and a count variable and see what the results are.
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!