TableUtils not working in script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 04:13 PM
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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 07:45 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 08:18 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 03:42 PM
I tried both the scripts it is not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 03:50 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 04:09 PM
Tried the above code no luck