TableUtils not working in script include

dhathrianoop
Giga Expert

I have included TableUtils in script include (not working)..however it worked when  I ran in background script



var tu = new global.TableUtils(sysClass);
var classHierarchy = tu.getTables().toArray();
ciClassH=classHierarchy.join(':');


var ciParentTable=['cmdb_ci_hardware','cmdb_ci_appl','cmdb_ci','cmdb_ci_netgear','cmdb_ci_server'];
var hierarchyName=['Hardware Hierarchy','Application Instance Hierarchy','Independent Hierarchy','Network Hierarchy','Server Hierarchy'];
for(var x=0;x<classHierarchy.length;x++)
{
var arrayUtil = new ArrayUtil();
if(arrayUtil.indexOf(ciParentTable, classHierarchy[x])>-1)
{
TableHierarchy=
hierarchyName[arrayUtil.indexOf(ciParentTable,classHierarchy[x])];
break;
}
}
tableHierarchy=TableHierarchy;

13 REPLIES 13

SanjivMeher
Kilo Patron
Kilo Patron

Add few debug statements in your script include to identify whats going wrong. Also i change line marked in bold below. please try again

 

var tu = new global.TableUtils(sysClass);
var classHierarchy = tu.getTables().toArray();
ciClassH=classHierarchy.join(':');


var ciParentTable=['cmdb_ci_hardware','cmdb_ci_appl','cmdb_ci','cmdb_ci_netgear','cmdb_ci_server'];
var hierarchyName=['Hardware Hierarchy','Application Instance Hierarchy','Independent Hierarchy','Network Hierarchy','Server Hierarchy'];
for(var x=0;x<classHierarchy.length;x++)
{
var arrayUtil = new ArrayUtil();
if(arrayUtil.indexOf(ciParentTable)>-1)
{
TableHierarchy=
hierarchyName[arrayUtil.indexOf(ciParentTable)];
break;
}
}
tableHierarchy=TableHierarchy;

 

Please mark this response as correct or helpful if it assisted you with your question.

Hi , only the below script is not working

 

var tu = new global.TableUtils(sysClass);
var classHierarchy = tu.getTables().toArray();
ciClassH=classHierarchy.join(':');

What is the value of sysClass? Has it been defined somewhere?

More of question from my side, doesn't the getTables  method give the array of hierachy table list. So do you need toArray still?

One more thing. As getTables underTableUtils gives a arraylist. Hence you need to use j2js to convert to java script array type.

var tu = new global.TableUtils(sysClass);
var classHierarchy = j2js(tu.getTables());//this give javascript array of the hierarchy tables of sysClass table that you have defined.