Return list of table extensions using TableUtils() utility
I always wonder, Is there any simple utility in ServiceNow to fetch the list of hierarchy/table extensions? ![]()
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
getTableExtensions() : Returns list of table extensions
var hierarchyList = new TableUtils('cmdb_ci_server').getTableExtensions();
gs.print(hierarchyList); //Displays all its extensions
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
Now, Let's iterate over the output. The output was displayed as an array list however, it's not an array ![]()
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]);
}
I hope you like my article ![]()
Kindly, Post comments if any corrections are required
Regards,
Sai Kumar
Labels:
https://www.servicenow.com/community/developer-articles/return-list-of-table-extensions-using-tableutils-utility/ta-p/2316751
