How to get the parent table name of a record in a child table?

Mike278
Kilo Explorer

Hi, how would I get the parent table name of a record?

For example, cmdb_ci_netgear table extends cmdb_ci_hardware table.

The code looks as follows:

var ci = new GlideRecord('cmdb_ci_hardware');

ci.get('123456789'); //looking for a specific sys_id in the Hardware table - in this case just random numbers

gs.addInfoMessage(ci.sys_class_name); 

This code returns "cmdb_ci_netgear", but how do I make it return "cmdb_ci_hardware" by looking up what the parent table is of that particular record? In other words, how to dot walk use a record in cmdb_ci_netgear table to figure out what its parent table is.

Thanks.

4 REPLIES 4

Elijah Aromola
Mega Sage

You could do:

var ci = new GlideRecord('cmdb_ci_hardware');

ci.get('123456789'); 

var tu = new TableUtils(ci.sys_class_name); 
var tables = tu.getTables()
var arrayUtil = new ArrayUtil();
var parentTable = arrayUtil.convertArray(tables)
parentTable = tables[1]

 

Sumanth16
Kilo Patron

Utpal Dutta1
Mega Guru

Hey Mike,

I've used below code to get data of Problem table's parent Incident in Business Rule. Maybe this code will help you figure out your solution:

 

var gr = new GlideRecord('incident');
gr.addQuery('sys_id',current.parent); //Current is for Problem Table in my case
gr.query();

 

If my reply helps then please mark it Helpful as well as Correct.

 

Thanks and Regards:

Utpal Dutta

DxSherpa Pvt. Ltd.

Sajilal
Mega Sage

current.parent in your addQuery condition should do the trick.

Please Mark Correct if this solves your issue and also mark 👍 Helpful if it helps resolve your problem.

Thanks,
Saji