
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 08:29 AM
Hi,
By using the below script
var table = new GlideRecord('cmdb_ci');
table.addEncodedQuery('sys_class_nameINSTANCEOFcmdb_ci_server');
table.query();
while(table.next()){
gs.log(table.sys_class_name);
}
Then the output is giving
cmdb_ci_aix_server,cmdb_ci_unix_server,cmdb_ci_win_server etc.
I want a script so that if i given cmdb_ci_aix_server, i want a output that this class is a Instanceof cmdb_ci_server class.
Is this possible
Thanks
Sai Krishna
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 07:15 PM
The issue is that cmdb_ci_aix_server has multiple levels of hierarchy. You'll need some intelligent way to determine at exactly which level you want to stop. Yes, cmdb_ci_aix_server extends cmdb_ci_unix_server, which in turn extends cmdb_ci_server, but then cmdb_ci_server extends cmdb_ci_computer, which extends cmdb_ci_hardware, which extends cmdb_ci, which extends cmdb.
The question is, how do you know that you want cmdb_ci_server, versus any of the other tables in the chain? Do you have an array of "base" tables that, when you reach one of those, you consider the hierarchy resolved? If so, this code demonstrates how to resolve whether your table extends one of your designated base tables:
(function() {
var extendedTable = 'cmdb_ci_aix_server';
var baseTables = [
'cmdb_ci_ups',
'cmdb_ci_printer',
'cmdb_ci_server',
'cmdb_ci_database',
'cmdb_ci_business_app',
// ...and so on
];
var aUtil = new ArrayUtil();
var tUtil = new TableUtils(extendedTable);
var tables = tUtil.getTables();
var msg = '';
for (var index = 0; index < tables.size(); index++) {
if (aUtil.contains(baseTables, tables.get(index))) {
msg = 'Table ' + extendedTable + ' is extended from ' +
tables.get(index) + '.';
break;
}
}
if (!msg)
msg = 'Table ' + extendedTable + ' not extended from any ' +
'table in the base table hierarchy.';
gs.info(msg);
})();
If, on the other hand, you just want to see if your table extends from cmdb_ci_server at any level, that's easy enough to do:
(function() {
var extendedTable = 'cmdb_ci_aix_server';
var baseTable = 'cmdb_ci_server';
var tUtil = new TableUtils(extendedTable);
var tables = tUtil.getTables();
var msg = 'Table ' + extendedTable + ' does ';
if (tables.indexOf(baseTable) < 0)
msg += 'not ';
msg += 'extend from ' + baseTable + '.';
gs.info(msg);
})();
Does that help get in the neighborhood of what you're looking for? If not, how exactly are you determining which table in the hierarchy you're looking for?
Hope this helps,
--Dennis R

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 09:55 AM
I didn't understand your question. What is your expected output
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
09-26-2018 10:03 AM
I want back of InstanceOf
means if was given cmdb_ci_aix_server i want answer as cmdb_ci_server or
if was given ,cmdb_ci_win_server i want answer as cmdb_ci_server.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2018 11:58 AM
You can also try this
var db = new GlideRecord('sys_db_object');
db.addQuery('sys_class_name','cmdb_ci_aix_server');
db.query();
if (db.next())
{
gs.log(db.super_class.sys_class_name);
}
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
09-26-2018 12:45 PM
If you just want the immediate parent of a table, the easiest thing to do is query the sys_db_object table as Sanjiv mentioned above. Note that you probably won't be able to do this client-side for most users due to restrictions on the cmdb_ci tables.
If you need more info about the table hierarchy, take a look at the TableUtils script include. It's got functions to get the absolute base table (the top of the hierarchy), all parent tables in the hierarchy up to the top, and all parents/children in the hierarchy.
Hope this helps,
--Dennis R