- 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 04:12 AM
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
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 04:23 AM
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
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 04:24 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 04:34 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2021 04:36 AM
Hey upendra ,
i trying to find logic, when do we use hasNext() in Script,i want to know that.