Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

What JS type does the TableUtils.getAllExtensions('tablename') function return?

JeremiP
Kilo Sage

What JS type does TableUtils.getAllExtensions('tablename') return?
I need to use this function to retrieve all tables extending cmdb_ci, and then fetch their display names.

Afterwards, I'd make a script where it updates a sys_choice list for a Table Name field.

But, it seems that the .getAllExtensions() function creates not an array, not a string, but an object.

Trying to make it into a String doesn't work out.

gs.debug("Running 'Get cmdb_ci table names' scheduled script.");

    //Getting the TableUtils API
var table = new TableUtils("cmdb_ci");
    //Querying for all tables extending cmdb_ci
var tableList = table.getAllExtensions();
    //We want to make this into an object (typeof tableList otherwise returns 'object')
tableList = tableList.toString();

gs.debug("tableList of type " + typeof tableList + " == " + tableList);

tableList = tableList.slice(0, tableList.length-1);
gs.debug("Slicing of tableList of type: " + typeof tableList + " here: " + tableList);

tableList.split(",");
gs.debug("Checking index 0 of tableList:" + tableList[0]);
gs.debug(tableList[1]);

 

The end goal is making a Category/Classifications field on the incident form, which gets filtered by the chosen CI record's Class value. Dependent Field did not work, as it seems that dot walking (cmdb_ci.class) is not returning the proper value, plus it's not possible to have multiple values in the Dependent value. I decided to try making it a reference field instead, which would use an advanced reference qualifier to look up which records in the list should get displayed.

1 ACCEPTED SOLUTION

Michael_Nau
Giga Contributor

Hi,

it returns a Java ArrayList.

Here's what you need to do to work with the return value in JS:

 

gs.include('j2js');
var tu = new TableUtils(table);
var extensions = j2js(tu.getAllExtensions());



Hope that helps.
Regards, Michael

View solution in original post

1 REPLY 1

Michael_Nau
Giga Contributor

Hi,

it returns a Java ArrayList.

Here's what you need to do to work with the return value in JS:

 

gs.include('j2js');
var tu = new TableUtils(table);
var extensions = j2js(tu.getAllExtensions());



Hope that helps.
Regards, Michael