GlideRecord.getValue is not returning the field value

Dustin9
Kilo Expert

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');
}

 

1 ACCEPTED SOLUTION

Peter Bodelier
Giga Sage

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.

 

PeterBodelier_0-1687352941346.png

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

4 REPLIES 4

Kalyani Jangam1
Mega Sage
Mega Sage

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

Peter Bodelier
Giga Sage

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.

 

PeterBodelier_0-1687352941346.png

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

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 🙂

Dustin9
Kilo Expert

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.