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

Can you try below. Also are you passing the correct value on sysClass

 

var tu = new global.TableUtils(sysClass);
var classHierarchy = tu.getTables().split(',');


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

Chris Sanford1
Kilo Guru

As was previously stated you need to use j2js, as the TableUtils class returns a Java arrayList which is a construct that doesn't exist in Javascript.

var tu = new global.TableUtils(sysClass);
var classHierarchy = j2js(tu.getTables());


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'];
var tableHierarchy = '';
breakHere: for(var x=0;x<classHierarchy.length;x++) {
   var arrayUtil = new ArrayUtil();
   var key = arrayUtil.indexOf(ciParentTable, classHierarchy[x]);
   if(key > -1) {
      tableHierarchy = hierarchyName[key];
      break breakHere;
   }
}

 

One other suggestion, is that you may want to use nested if blocks to check some of these 'parent tables' in the hierarchy, as many of them are direct super classes of each other. For example, cmdb_ci_netgear and cmdb_ci_server are both extensions of cmdb_ci_hardware, which is an extension of cmdb_ci, so you would have very unpredictable results if your 'sysClass' was, for example an extension of the server table.

chidanandadhath
Kilo Guru

I tried both the scripts it is not working 

Can you try this

 

var tu = new global.TableUtils(sysClass);

var classHierarchy = tu.getTables().toString().replace('[','').replace(']','').split(',');


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

Tried the above code no luck