is not a function - error

Jamsta1912
Tera Guru

Hello,

When I run this script below as a background script, I get back a list of incident sys_ids, as expected:

var rec = new GlideRecord('incident');

rec.query();

while(rec.next()){

  gs.print('The record sys_id is: ' + rec.sys_id);

}

But when I run this one below, hoping to get back a list of template sys_ids:

var rec = new GlideRecord('sys_template');

rec.query();

while(rec.next()){

  gs.print('The record sys_id is: ' + rec.sys_id);

}

I instead get this:

Evaluator: org.mozilla.javascript.EcmaError: is not a function.

  Caused by error in script at line 4

  1: var rec = new GlideRecord('sys_template');

  2: rec.query();

  3: while(rec.next()){

==> 4: gs.print('The record sys_id is: ' + rec.sys_id);

  5: }

Evaluator: org.mozilla.javascript.EcmaError: is not a function.

  Caused by error in script at line -1

Can anyone explain what's going on here?

Thanks

Jamie

1 ACCEPTED SOLUTION

adiddigi
Tera Guru

on sys_template, there is already a column called "next", hence the error.


you should be using _next()




  1. var rec = new GlideRecord('sys_template');  
  2. rec.query();  
  3. while(rec._next()){  
  4.   gs.print('The record sys_id is: ' + rec.sys_id);  
  5. }  


http://wiki.servicenow.com/index.php?title=GlideRecord#_next


View solution in original post

2 REPLIES 2

adiddigi
Tera Guru

on sys_template, there is already a column called "next", hence the error.


you should be using _next()




  1. var rec = new GlideRecord('sys_template');  
  2. rec.query();  
  3. while(rec._next()){  
  4.   gs.print('The record sys_id is: ' + rec.sys_id);  
  5. }  


http://wiki.servicenow.com/index.php?title=GlideRecord#_next


A-ha... yes, I'm sure I've come across this before!


Thank you Abhi - speedy response