How to find the parent table

ncp
Mega Guru

All,

Is there an easy way to just get the parent table of a current table? I have an array of model categories - cmdb_ci_win_server, cmdb_ci_linux_server and cmdb_ci_server. In this scenario, cmdb_ci_server is the parent of both the other model categories. Is there an easy way to identify the parent in this case via script? I looked at the tableutils script include and that gives hierarchy array. I was hoping for something simpler like getParent(). Any ideas?

 

Thanks

1 ACCEPTED SOLUTION

arielgritti
Mega Sage

Hello ncp

In the way you commented with the TableUtils what about to use getTables()?

 

find_real_file.png

If you are looking the "parent" of the incident table you obtain [incident, task]

 

Please, mark correct or useful if I helped you
Thanks
Ariel

View solution in original post

4 REPLIES 4

arielgritti
Mega Sage

Hello ncp

In the way you commented with the TableUtils what about to use getTables()?

 

find_real_file.png

If you are looking the "parent" of the incident table you obtain [incident, task]

 

Please, mark correct or useful if I helped you
Thanks
Ariel

ncp
Mega Guru

Thanks Ariel, I was hoping for a simple getParent(), for cmdb_ci_win_server I get the following, so have to go through those,but if thats the only option then I dont have a choice. Thanks for your input. If I dont get a better answer I will mark yours as the correct one ariel

 

cmdb_ci_win_server, cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb


Priyanka136
Mega Guru

Hi ncp,

Checkout the TableUtils script include for some helpers. getTables() will return all the parent tables, the last entry is the base table.

var tu = new TableUtils("cmdb_ci_win_server");
var tables = tu.getTables();
//tables = [cmdb_ci_win_server, cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci]

One clarification regarding the user of getTableName() - the result can vary depending on the GlideRecord.

Say I have INC0010003, and I have an "incident" GlideRecord for that sys_id. getTableName() will give "incident". If, however, my GlideRecord is on "task" for that same record, getTableName() will give "task".

getRecordClassName(), on the other hand, will give "incident" for both. It returns the sys_class_name value. For conditions on class, it is often more reliable.

Let me know, if you have any question.

Please mark it Correct or Helpful, if it works based on impact...!!!!

Thanks,

Priyanka

www.dxsherpa.com

Ani16
Kilo Contributor

May someone know how to do the same thing using only the API? 

 

Thanks,

Ani