When do we use next(), hasNext() and _next()

chanikya
Kilo Sage

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()

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

25 REPLIES 25

Hi,

nope

you need to use next() method so that it goes to that record and then update it

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@chanikya 

Let me know if I have answered your question.

If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

var gr=new GlideRecord('incident');

gr.addQuery('category','software');

gr.query();

if(gr.hasNext())

{

if(gr.next())

{

gr.description="ABC";

gr.update();

}

}

is it correct ? to check Query condition ?

Your code will run only once. To update all the records use below code

var gr=new GlideRecord('incident');
	gr.addQuery('category','software');
	gr.query();
	while(gr.next())
	{
		gr.description="ABC";
		gr.update();
	}

 

Hey upendra ,

i trying to find logic, when do we use hasNext() in Script,i want to know that.