- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2023 04:02 PM
Hello.. I'm working on the simplest GlideRecord query for a fix script and I'm not able to get the value of a field using .next() method. However, I am able to get the value using .get() method. See gr1 and gr2 below. Both scripts are doing the same exact thing for the same sys_id, but using .next() does not retrieve a value. I know the query works, because getRowCount() returns 1. Not sure if I've lost my mind, but cannot figure out what's going on here....
var gr1 = new GlideRecord('sys_template');
gr1.get('<sys_id>');
gs.info(gr1.getValue('name');
var gr2 = new GlideRecord('sys_template');
gr2.addQuery('sys_id', '<sys_id>');
gr2.query();
if (gr2.next()) {
gs.info(gr2.getValue('name');
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 06:04 AM - edited ‎06-21-2023 06:09 AM
It looks like you are missing ) in your script, which may give some wrong feedback.
var gr1 = new GlideRecord('sys_template');
gr1.get('<sys_id>');
gs.info(gr1.getValue('name'));
var gr2 = new GlideRecord('sys_template');
gr2.addQuery('sys_id', '<sys_id>');
gr2.query();
if (gr2._next()) {
gs.info(gr2.getValue('name'));
}
Apart from that, Kalyani's answer is correct, but doesn't explain why.
The sys_template table contains a field 'next'. Which interferes with you calling the next() function. This is why you will need to use _next() here.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 06:01 AM
Hi @Dustin9
Try Below code
var gr2 = new GlideRecord('sys_template');
gr2.addQuery('sys_id','98f0b467b70333008321e916de11a934'); // sys_id of your template
gr2.query();
gs.info(gr2);
if(gr2._next())
{
gs.info("In ifff");
gs.info(gr2.getValue('name'));
}
use _next() instead next(), it will solve your issue
Please Mark Helpful and Correct if it really work you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 06:04 AM - edited ‎06-21-2023 06:09 AM
It looks like you are missing ) in your script, which may give some wrong feedback.
var gr1 = new GlideRecord('sys_template');
gr1.get('<sys_id>');
gs.info(gr1.getValue('name'));
var gr2 = new GlideRecord('sys_template');
gr2.addQuery('sys_id', '<sys_id>');
gr2.query();
if (gr2._next()) {
gs.info(gr2.getValue('name'));
}
Apart from that, Kalyani's answer is correct, but doesn't explain why.
The sys_template table contains a field 'next'. Which interferes with you calling the next() function. This is why you will need to use _next() here.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 08:18 AM
Hey @Peter Bodelier - thanks for the detailed response. Yes, I was able to look into this early this morning after a good night's sleep, and I noticed the OOB field called next in sys_template. I was able to find where others were having issues looping through sys_template records as well and saw the ._next() method to be used in these scenarios. Definitely good knowledge to know. Thank you again! Made the updates and got my fix script work 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 07:28 AM
Hey Guys - thanks for the feedback. I was able to figure it out this morning after a good night's sleep. I noticed that sys_template has an OOB field named next this morning, and did some googling in the community to see if other users were having issue looping through records in sys_template and came across the ._next solution. Finally got my fix script to work after applying the change and very good info to have. Thank you all, and thanks Peter for the thorough explanation. Much appreciated.