hasNext() and _next() examples
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 10:05 AM
Any one can be provide the hasNext() and _next() examples.
Please help any one.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 10:11 AM
Hi @vinod6 ,
If you want to update the records you can use next() method
next() - goes to every record
hasNext() - tells whether there is record satisfying the query
_next() - used when your table field/column name as "name".
Thanks,
Danish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:05 AM
@vinod6 Here is answer to your question with example.
- hasNext()
Determines if there are any more records in the GlideRecord.
var now_GR = new GlideRecord('kb_knowledge');
now_GR.query();
if (now_GR.hasNext()) {
gs.info('Record found'); // found it, do it
} else {
gs.info('Record not found'); // didn't find it
}
- _next()
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.
var rec = new GlideRecord('sys_template');
rec.query();
while (rec._next()) {
gs.print(rec.number + ' exists');
}
Please mark this answer helpful and correct if it has answered your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:08 AM
Hi there,
There are loads of them already in an out-of-the-box instance.
What is your real question?
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field