Difference between query() and _query() , next() and _next()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2025 10:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2025 12:54 AM
Hello @SeemaJenitT ,
Just wanted to check in to see if my earlier response helped you out or if you're still facing any issues. If your query is resolved, it would be great if you could mark my reply as helpful and accept it as the solution — that way it can also benefit others who come across the thread later.
Also, if you found any other responses helpful, feel free to mark those as helpful too. You can even accept multiple solutions if they contributed to resolving your issue.
Let me know if you need anything else!
Best regards,
Aniket Chavan
ServiceNow MVP 2025 | ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @SeemaJenitT ,
Just wanted to check in to see if my earlier response helped you out or if you're still facing any issues. If your query is resolved, it would be great if you could mark my reply as helpful and accept it as the solution — that way it can also benefit others who come across the thread later.
Also, if you found any other responses helpful, feel free to mark those as helpful too. You can even accept multiple solutions if they contributed to resolving your issue.
Let me know if you need anything else!
Best regards,
Aniket Chavan
ServiceNow MVP 2025 | ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2025 06:52 AM
Hey @SeemaJenitT ,
I have summarized the difference between these 4 methods for you. See table below.
When working with GlideRecord in ServiceNow, you may encounter both standard methods and "underscore" methods. These serve similar purposes with subtle but important differences
Method Standard Use When to Use Underscore Version
query() | Standard record retrieval | If your table has a field named query |
_query() | Same as query() | To avoid conflict with a query field |
next() | Standard record iteration | If your table has a field named next |
_next() | Same as next() | To avoid conflict with a next field |
Always use the standard query() and next() unless you specifically have fields named query or next in your table schema—in those cases, use _query() and _next() to prevent script errors and ensure reliable operation.
1. query()
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
// process records
}
2. _query()
var gr = new GlideRecord('custom_table');
gr._query(); //you will see this method used in OOTB widgets whenver they query on the tables.
while (gr.next()) {
// process records
}
3. next()
while (gr.next()) {
// process the current record
}
4. _next()
while (gr._next()) {
// process records safely even with a 'next' field
}
Thanks,
Bhimashankar H
---------------------------------------------------------------------------------------------------------
If my answer helps you or resolves your query, please consider marking as 'Helpful'/'Accept As Solution'. So future readers with similar questions can find it easily. Your coordination will help community to grow stronger!.
----------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2025 10:53 PM
I hope you saw my reply.
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. It will help future readers as well having similar kind of questions and close the thread.
Thanks,
Bhimashankar H