Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 05:41 PM
I want to populate CMDB hierarchy for example if cmdb_ci_computer is the CI Class Row, then the end of the row should look something like this cmdb: cmdb_ci : cmdb_ci_hardware: cmdb_ci_computer
basically want to populate hierarchy of CI class
Solved! Go to Solution.
Labels:
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 05:57 AM
Jeah, i forgot one part. The below one should work:
function getParentTables(childTableName)
{
var parentTables = [];
var table = new GlideRecord('sys_db_object');
table.addQuery('name', childTableName);
table.addNotNullQuery('super_class');
table.query();
if(table.next())
{
var parentTableName = table.super_class.name;
parentTables.push(parentTableName);
// get the parents of the parent and appen it
parentTables = parentTables.concat(getParentTables(parentTableName));
}
return parentTables;
}
Greetings
Fabian
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2023 09:44 AM
If you want to exclude some class like the base cmdb table and using and static method in some Script Include:
CMDB_Utils.getParentTables = function (childClassName, arr) {
try {
var parentClasses = arr || [];
var encodedQuery = 'name=' + childClassName;
var cmdbGr = new GlideRecord(_CONSTS.SYS_DB_OBJECT_TABLE);
cmdbGr.addEncodedQuery(encodedQuery);
cmdbGr.addNotNullQuery(_CONSTS.SUPER_CLASS_FIELD);
cmdbGr.setLimit(1);
cmdbGr.query();
if (cmdbGr.next()) {
var parentClassName = String(cmdbGr[_CONSTS.SUPER_CLASS_FIELD][_CONSTS.NAME_FIELD]);
if (parentClassName !== _CONSTS.CMDB_TABLE) {
parentClasses.push(parentClassName);
// Gettting the next parents recursively.
CMDB_Utils.getParentTables(parentClassName, parentClasses);
}
}
return parentClasses;
} catch (err) {
DevUtils.log(err.message, _CONSTS.ERR_LOG_PROPERTY, _TYPE);
}
};