- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 02:26 AM
Hi All,
I have 10 records only on whole table , now I want to update records So
When do we use next(), hasNext() and _next()
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 02:59 AM
Hi,
just to check if there is any record satisfying the query
hasNext() - does not actually go to that record but just tells true/false is there is any record matching the query
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 05:33 AM
while loop will only run till gr.next() record is not null. So there is no need to use hasNext()
while(gr.next())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 05:00 AM
Hi,
it's correct syntax
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 06:01 AM
I could see you marked my response as correct earlier and now it is not.
Would you mind marking my response as correct if I was able to help you.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 02:42 AM
Hi Chanikya,
hasNext() : hasNext() method returns true if iterator have more elements.
next() : next() method returns the next element and also moves to the next element.
_next() : is method similar to next() in GlideRecord.
Moves to the next record in the GlideRecord. Provides the same functionality as next(), intended to be used in cases where the GlideRecord has a column named next.
Example:-
So I could do:
gr.query();
if (gr.next()) {
gr.field = 'value';
gr.update();}
but this won't update anything:
gr.query();
if (gr.hasNext()) {
gr.field = 'value';
gr.update();}
So if there are one or more records contained in your gr set, hasNext() will return true.
Please mark my reply as Correct & Helpful, if applicable.
Thanks
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 02:49 AM
if we want to use hasnext() in script then do we have to use like below?
gr.query()
while(gr.hasNext())
{
if(gr.next())
{
gr.description='welcome';
gr.update();
}}