How to get table hierarchy in Scoped applications

Sandeep132
Kilo Sage

Hi all,

I am trying to get table hierarchy for a particular table using TableUtils script include. This is working fine for Global applications. If i apply the same for scoped applications i am getting "Illegal access to Script include" error because the TableUtils script include is restricted to only Global application.

Is there any other way to access the table hierarchy in scoped applications?

Thanks.

7 REPLIES 7

chidanandadhath
Kilo Guru

I'm using TableUtils in script include....below is the script...getTables contains GlideDBObjectManager

 

var tu = new global.TableUtils(sysClass);
var classHierarchy = tu.getTables().toArray();
ciClassH=classHierarchy.join(':');

Brent Llewellyn
Mega Guru

GlideTableHierarchy is the API used to get get table hierarchy in Scoped applications.

 

Specifically the code below will get it

var table = new GlideTableHierarchy("cmdb_ci_server"); 
gs.info(table.getTables());

 

Please mark helpful or correct if this solves your problem. 

 

Thanks,

Brent

Jean Ferreira
Giga Guru

You can create your own getTables method:

 

function getTables(parentTable) {
    var hierarchy = [];
    var dbObjectGr = new GlideRecord('sys_db_object');

    hierarchy.push('' + parentTable);

    dbObjectGr.addQuery('name', parentTable);
    dbObjectGr.query();

    while (dbObjectGr.next()) {
        parentTable = dbObjectGr.super_class.name;

        if (parentTable != '') {
            hierarchy.push('' + parentTable);
            dbObjectGr = new GlideRecord('sys_db_object');
            dbObjectGr.addQuery('name', parentTable);
            dbObjectGr.query();
        }
    }

    return hierarchy;
}

 

Please mark as helpful in case it helped you.

Please mark as solved in case it worked for you use case.