Check when there is NOT a next record when using GlideRecord

JJG
Kilo Guru

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?

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

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!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

1 REPLY 1

Michael Jones -
Giga Sage

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!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!