- 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 02:54 AM
Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 03:58 AM
kindly hep me for understanding
if there is a single record in whole table ? then how will hasNext() will works ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 04:27 AM
Hi Chanikya,
The basic understanding for hasNext() is usually used to check there's another step to be taken.
If, for example, your query returns three records, you might call .next() after the query to get the first record. At this point, hasNext() will return true. Calling next() again to get the second record will leave us with one left, so once again, hasNext() will return true. However, calling next() one more time will populate the third and final record into the GlideRecord object. There being no further additional records to grab, if we call hasNext() once more at this point, it will return false.
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 05:10 AM
Hi,
Lets we take 3 records to update INC001001,INC001002, INC001003
var gr=new GlideRecord('incident');
gr.addQuery('category','software');
gr.query();
while(gr.hasNext())
{
if(gr.next())
{
gr.description="ABC";
gr.update();
}
}
REsult :
first level- TRue : INC001001.description =ABC
Second level -True: INC001002.description =ABC
third level- False: INC001003.description=
INC001003 will not be updated.
is it Correct ?
So then how to update INC001003.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 05:35 AM
Yes if query not returning all the 3 records.