hasNext() and _next() examples

vinod6
Tera Contributor

Any one can be provide the hasNext() and _next() examples.

Please help any one.

 

Thanks.

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

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

 

Sandeep Rajput
Tera Patron
Tera Patron

@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
}


Source:
https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/c_GlideRecordAPI#r_GlideR...

  • _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');
}

Source: https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/c_GlideRecordAPI#r_GlideR...

 

Please mark this answer helpful and correct if it has answered your question.

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn