The Zurich release has arrived! Interested in new features and functionalities? Click here for more

GlideRecord next() call fails - why?

ianj
Kilo Expert

I am attempting to run the following code in a test workflow:

 

var gr = new GlideRecord('sys_template');

var query_name = 'RBA - Network - KMTC VIP';

 

gr.addQuery('name', query_name);

gr.query();

 

if (gr.hasNext())

{

      workflow.info('hasNext() says we have a next() available');

      workflow.info('the reported name (should be empty): "' + gr.name + '"');

      // why is this throwing an error?

      gr.next();

      workflow.info("next() call has succeeded - we won't get to here");

}

 

When the code gets to the gr.next()call, the workflow fails (the Run Script block turns red), and the following error shows up in the context log:


  Execption in Activity Handler:Log Object
  Object
  lineNumber: string = 16
  sourceName: string = <refname>#17(eval)
  name: string = TypeError
  message: string = is not a function.


This appears to be table-specific, as changing to a different table (such as incident or change_request) works correctly.   I'm asking my admin to look into it, but we're all new to SN, so I figured I'd see if anyone else has seen this behavior before, and what it might mean.   We have a theory it may be something around permissions, but that is at best a moderately informed conjecture.

1 ACCEPTED SOLUTION

For what it's worth, this code exhibits the exact same problem:



var gr = new GlideRecord('sys_template');


gr.query();




gr.next();




It turns out that there is a field in sys_template called 'next'.   If we call gr._next(), it works properly.   The lesson is to check the fields in the table.


View solution in original post

7 REPLIES 7

I agree. I also agree that referencing fields before next() has been called can yield unpredictable results.



Is there something fishy about that particular record? Are you able to open it some other way?



Would the following code also give an exception?



var gr = new GlideRecord('sys_template');


if (gr.get('name','RBA - Network - KMTC VIP')) {


      gs.addInfoMessage('got to here okay with ' + gr.getDisplayValue();


}




For what it's worth, this code exhibits the exact same problem:



var gr = new GlideRecord('sys_template');


gr.query();




gr.next();




It turns out that there is a field in sys_template called 'next'.   If we call gr._next(), it works properly.   The lesson is to check the fields in the table.


Oops, yes.. I remember now.. I faintly remember a post by Mark some time back. Thanks Ian.