- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 01:26 AM
Hi All,
I understand that hasnext() will either return true or false, but next() also in a way does the same thing and then goes to the next record.
I would like understand when should we use hasnext(), Is there any case scenario where usage of hasnext() is important
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2017 05:34 AM
Although the question has been answered, you may find reading up about an iterator explains a bit about the underlying purpose of these two methods.
Suggested reading: https://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html
For what it's worth, consider standing near the edge of a cliff:
- hasNext() is usually used to check there's another step to be taken
- next() takes that step.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 09:49 AM
hasNext() : hasNext() method returns true if iterator have more elements.
next() : next() method returns the next element and also moves to the next element.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2017 06:48 PM
hasNext() is a little lighter weight since it just returns a true/false where next() actually returns and steps you into the next gliderecord. I would say if your goal is just to determine whether the GlideRecord set has records then use hasNext(), but if you need to manipulate or use values from one or more of the records returned you'll want to use .next().

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2017 05:05 AM
Hi Sohan,
Good Day
hasNext() - will be used if there are any more records while GlideRecord.
RestAPIRequestBody - hasNext()
Determine if there are additional entries in the request body.
Use this method with the nextEntry() method to iterate over multiple request body entries.
Eg:
var requestBody = request.body;
requestBody.hasNext(); // returns true if the request contains a single entry or multiple entries
//calling second time
requestBody.hasNext(); // returns false if the request contains a single entry, or true if the request contains multiple entries
Thanks,
Priyanka R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2017 05:34 AM
Although the question has been answered, you may find reading up about an iterator explains a bit about the underlying purpose of these two methods.
Suggested reading: https://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html
For what it's worth, consider standing near the edge of a cliff:
- hasNext() is usually used to check there's another step to be taken
- next() takes that step.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2020 06:58 AM
I'm finding that hasNext does not work, it returns "undefined" instead of true so that the script can move on.
while(check.next()){
works to move on and do things reliably
if(check.hasNext()){
does not work in weird ways. In a background script it returns undefined instead the result of the if statement. This seems to cause the if to evaluate true erratically instead of per the condition being true or false. Why that evaluation is erratic as well is really baffling.
Thoughts?