TypeError: is not a function

pennieturner
Mega Guru

Hi there

I'm in need of some scripting help!  

I'm trying to run a Business Rule on the template table.

Conditions are to run when a template has been made inactive.   I want it to then check if there are any other active templates with the same name.

That bit works fine.

Its when I get to do the if statement it keeps erroring with 'TypeError: is not a function'

See below the script:

function checkForActiveTemps() {

  try{

  var activeBSTemp = new GlideRecord ('sys_template');

  activeBSTemp.addQuery('table','u_access_management');

  activeBSTemp.addQuery('name',current.name);

  activeBSTemp.addQuery('active','true');

  activeBSTemp.query();

  gs.log("ive got this many in my query - " +activeBSTemp.getRowCount());

  if(activeBSTemp.next()) {

  gs.log('i have something');

  }

  }

  catch(err) {

  gs.log("BR - check audit on BS error: " + err);

  }

}

checkForActiveTemps();

The details are correct in that the logs show how many I have in my query, but when I try and do something with it, I get the error below:


BR - check audit on BS error: TypeError: is not a function

ive got this many in my query - 0

Any ideas how to fix this as I really can't figure out where the problem is

Thank you in advance

1 ACCEPTED SOLUTION

Hello Pennie,



As you are using the sys_template table. It contains a field by the name of next.



Please do the following modification in your script :


if(activeBSTemp.next()) replace it with   if(activeBSTemp._next())



Hope, this would resolve the issue.



Thanks,
Subhankar


View solution in original post

7 REPLIES 7

LearnerSubho
Mega Guru

Hello Pennie,



Could you please put the "checkForActiveTemps();" at the first line and check if it resolves the issue.



Thanks,


Subhankar


I tried it before I just tried it again and the same error


Hello Pennie,



As you are using the sys_template table. It contains a field by the name of next.



Please do the following modification in your script :


if(activeBSTemp.next()) replace it with   if(activeBSTemp._next())



Hope, this would resolve the issue.



Thanks,
Subhankar


Thank you, that has worked.



So the error was because on the table there was a field called Next? Would you mind just explaining out the _next() works please so I know for futurer?



Thank you!!!