logo

NJP

Return list of table extensions using TableUtils() utility

Import · Dec 27, 2021 · article

I always wonder, Is there any simple utility in ServiceNow to fetch the list of hierarchy/table extensions? image

Well, By OOB we have TableUtils(). It contains multiple functions to perform on a table.

I will walk you through a few interesting functions.

getTables() : Returns list of table names in the table parent hierarchy

var hierarchyList = new TableUtils('cmdb_ci_server').getTables();
gs.print(hierarchyList); //Displays all its parent hierarchy along with the input

image

getTableExtensions() : Returns list of table extensions

var hierarchyList = new TableUtils('cmdb_ci_server').getTableExtensions();
gs.print(hierarchyList); //Displays all its extensions

image

getAllExtensions() : Returns list of table extensions including base table

var hierarchyList = new TableUtils('cmdb_ci_server').getAllExtensions();
gs.print(hierarchyList); //Displays all its extensions including base 

image

Now, Let's iterate over the output. The output was displayed as an array list however, it's not an array image

It's an object and we have to convert it into an array as below

var hierarchyList = new TableUtils('cmdb_ci_server').getTables();
gs.print(hierarchyList);

var arr = hierarchyList.toArray(); //Convert the output into an array 
for(var i=0; i<arr.length; i++){ //Iteration
    gs.print(arr[i]);
}

image

I hope you like my article image

Kindly, Post comments if any corrections are required

Regards,

Sai Kumar

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/return-list-of-table-extensions-using-tableutils-utility/ta-p/2316751