---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# TableUtils - Global

# TableUtils - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes to read

The TableUtils script include provides shortcuts for accessing table related information.

This class is available to server-side scripts.

## TableUtils - TableUtils(String tableName) {#ariaid-title2}

Creates an instance of a TableUtils class.
{#r_TU-TableUtils_S__table_jm5_34v_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The table name |
[Table 1. Parameters]

{#r_TU-TableUtils_S__table_jm5_34v_4t}  

    var tu = new TableUtils("incident");

## TableUtils - drop(String tableName) {#ariaid-title3}

Drops a database table.
Note:  
Use with extreme caution. Dropping a table permanently deletes the table and all its data. If the table is extended, use dropTableAndExtensions.
{#r_TU-drop_S__table_ojq_gpv_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Name of the table to drop |
[Table 2. Parameters]

{#r_TU-drop_S__table_ojq_gpv_4t} {#r_TU-drop_S__table_pjq_gpv_4t__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 3. Returns]

{#r_TU-drop_S__table_pjq_gpv_4t}  

    var tu = new TableUtils();
    tu.drop("table_that_will_be_lost_forever");

Output:

    dropping table table_that_will_be_lost_forever
    Starting cache flush
    Cache flush complete
    TABLE DROP: admin dropped table table_that_will_be_lost_forever

## TableUtils - dropAndClean(String tableName) {#ariaid-title4}

Drops a database table and cleans up references to the table.
Note:  
Use with extreme caution. Dropping a database table permanently deletes the table and all its data. If the table is extended, use dropTableAndExtensions.
{#r_TU-dropAndClean_S__table_mb5_15v_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Name of the table to drop |
[Table 4. Parameters]

{#r_TU-dropAndClean_S__table_mb5_15v_4t} {#r_TU-dropAndClean_S__table_nb5_15v_4t__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 5. Returns]

{#r_TU-dropAndClean_S__table_nb5_15v_4t}  

    var tu = new TableUtils();
    tu.dropAndClean("table_that_will_be_lost_forever");

Output:

    dropping table table_that_will_be_lost_forever
    Starting cache flush
    Cache flush complete
    TABLE DROP: admin dropped table table_that_will_be_lost_forever
    *** Script: removing gauges for table_that_will_be_lost_forever
    *** Script: removing forms for table_that_will_be_lost_forever
    *** Script: removing styles for table_that_will_be_lost_forever
    *** Script: removing forms sections for table_that_will_be_lost_forever
    *** Script: removing lists for table_that_will_be_lost_forever
    *** Script: removing related lists for table_that_will_be_lost_forever
    *** Script: removing references to table_that_will_be_lost_forever
    *** Script: removing dictionary entries for table_that_will_be_lost_forever
    Background message, type:info, message: Table deleted

## TableUtils - dropTableAndExtensions(String tableName) {#ariaid-title5}

Drops a database table, all of it's extended tables, and cleans up references to the
tables.
Note:  
Use with extreme caution. Dropping a database table permanently deletes the table and all of its data.
{#r_TU-dropTableAndExtensions_S__table_yhf_r5v_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The table to drop |
[Table 6. Parameters]

{#r_TU-dropTableAndExtensions_S__table_yhf_r5v_4t} {#r_TU-dropTableAndExtensions_S__table_zhf_r5v_4t__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 7. Returns]

{#r_TU-dropTableAndExtensions_S__table_zhf_r5v_4t}  

    var tu = new TableUtils();
    tu.dropTableAndExtensions("table_that_will_be_lost_forever");

Output:

    dropping table parent_table_that_will_be_lost_forever
    Starting cache flush
    Cache flush complete
    TABLE DROP: admin dropped table ext_table_that_will_be_lost_forever
    removing gauges for ext_table_that_will_be_lost_forever
    removing forms for ext_table_that_will_be_lost_forever
    removing styles for ext_table_that_will_be_lost_forever
    removing forms sections for ext_table_that_will_be_lost_forever
    removing lists for ext_table_that_will_be_lost_forever
    removing related lists for ext_table_that_will_be_lost_forever
    removing references to ext_table_that_will_be_lost_forever
    removing dictionary entries for ext_table_that_will_be_lost_forever
    Background message, type:info, message: Table deleted
    dropping table parent_table_that_will_be_lost_forever
    Starting cache flush
    Cache flush complete
    TABLE DROP: admin dropped table parent_table_that_will_be_lost_forever
    removing gauges for parent_table_that_will_be_lost_forever
    removing forms for parent_table_that_will_be_lost_forever
    removing styles for parent_table_that_will_be_lost_forever
    removing forms sections for parent_table_that_will_be_lost_forever
    removing lists for parent_table_that_will_be_lost_forever
    removing related lists for parent_table_that_will_be_lost_forever
    removing references to parent_table_that_will_be_lost_forever
    removing dictionary entries for parent_table_that_will_be_lost_forever
    Background message, type:info, message: Table deleted

## TableUtils - getAbsoluteBase() {#ariaid-title6}

Returns the base table name from which the table was extended.
Note:  
For any table under the cmdb_ci hierarchy, this method returns cmdb_ci and not cmdb, which is the actual base table.
{#r_TU-getAbsoluteBase__table_c3f_gyv_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 8. Parameters]

{#r_TU-getAbsoluteBase__table_c3f_gyv_4t} {#r_TU-getAbsoluteBase__table_d3f_gyv_4t__entry__2}

| Type | Description |
|-|-|
| String | Base table name |
[Table 9. Returns]

{#r_TU-getAbsoluteBase__table_d3f_gyv_4t}  

    var table = new TableUtils("cmdb_ci_server");
    gs.print(table.getAbsoluteBase());

Output: cmdb_ci

## TableUtils - getAllExtensions() {#ariaid-title7}

Returns the list of tables that extend a table, includes the base table.
{#r_TU-getAllExtensions__table_yq3_gxv_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 10. Parameters]

{#r_TU-getAllExtensions__table_yq3_gxv_4t} {#r_TU-getAllExtensions__table_zq3_gxv_4t__entry__2}

| Type | Description |
|-|-|
| ArrayList | A list of tables that extend the table, includes the base table. |
[Table 11. Returns]

{#r_TU-getAllExtensions__table_zq3_gxv_4t}  

    var table = new TableUtils("task");
    gs.print(table.getAllExtensions());

Output:

    [task, incident, issue, kb_submission, sysapproval_group, change_request, change_request_imac, sc_task, 
    problem, sc_req_item, ticket, ast_transfer_order, planned_task, change_task, change_phase, sc_request]

## TableUtils - getHierarchy() {#ariaid-title8}

Returns a list of all classes participating in the hierarchy of the specified
table.
{#r_TU-getHierarchy__table_lbl_ryv_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 12. Parameters]

{#r_TU-getHierarchy__table_lbl_ryv_4t} {#r_TU-getHierarchy__table_mbl_ryv_4t__entry__2}

| Type | Description |
|-|-|
| ArrayList | A list of all classes in the specified table's hierarchy. |
[Table 13. Returns]

{#r_TU-getHierarchy__table_mbl_ryv_4t}  

    var table = new TableUtils("cmdb_ci_server");
    gs.print(table.getHierarchy());

Output: \[cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb_ci_mainframe,
cmdb_ci_linux_server, cmdb_ci_mainframe_lpar, cmdb_ci_esx_server, cmdb_ci_unix_server,
cmdb_ci_solaris_server, cmdb_ci_hpux_server, cmdb_ci_aix_server, cmdb_ci_osx_server,
cmdb_ci_netware_server, cmdb_ci_win_server\]

## TableUtils - getTables() {#ariaid-title9}

Returns the table hierarchy.
{#r_TU-getTables__table_z1t_3wv_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 14. Parameters]

{#r_TU-getTables__table_z1t_3wv_4t} {#r_TU-getTables__table_abt_3wv_4t__entry__2}

| Type | Description |
|-|-|
| ArrayList | A list of table names in the parent hierarchy. |
[Table 15. Returns]

{#r_TU-getTables__table_abt_3wv_4t}  

    // Get the hierarchy of tables
    var table = new TableUtils("cmdb_ci_computer");
    var tableArrayList = table.getTables();

    // Use the j2js method to convert the Java ArrayList to JavaScript
    gs.include("j2js");
    var tableArray = j2js(tableArrayList);

    // Write the value of each element in the JavaScript array
    var i = 0;
    while ( i < tableArray.length ) {
    gs.print("Table with index " + i + ": " + tableArray[i]);
    i++;
    }

Output:

    Table with index 0: cmdb_ci_computer
    Table with index 1: cmdb_ci_hardware
    Table with index 2: cmdb_ci
    Table with index 3: cmdb

## TableUtils - getTableExtensions() {#ariaid-title10}

Returns a list of tables that extend a table.
{#r_TU-getTableExtensions__table_sfl_twv_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 16. Parameters]

{#r_TU-getTableExtensions__table_sfl_twv_4t} {#r_TU-getTableExtensions__table_tfl_twv_4t__entry__2}

| Type | Description |
|-|-|
| ArrayList | A list of table names that extend the table. |
[Table 17. Returns]

{#r_TU-getTableExtensions__table_tfl_twv_4t}  
This example shows that 58 tables in this instance extend the Computer \[cmdb_ci_computer\]
table. (Output condensed below.)

    // Get the tables that extend the table
    var table = new TableUtils("cmdb_ci_computer");
    var tableArrayList = table.getTableExtensions();
     
    // Use the j2js method to convert the Java ArrayList to JavaScript
    gs.include("j2js");
    var tableArray = j2js(tableArrayList);
     
    // Write the value of each element in the JavaScript array
    var i = 0;
    while ( i < tableArray.length ) {
      gs.print("Table with index " + i + ": " + tableArray[i]);
      i++;
    }

Output:

    Table with index 0: cmdb_ci_mainframe_hardware
    Table with index 1: cmdb_ci_handheld_computing
    Table with index 2: cmdb_ci_ucs_blade
    Table with index 3: cmdb_ci_storage_switch
    Table with index 4: cmdb_ci_server
    Table with index 5: cmdb_ci_hmc_server
    ...
    Table with index 56: cmdb_ci_pc_hardware
    Table with index 57: cmdb_ci_ucs_rack_unit

## TableUtils - hasExtensions() {#ariaid-title11}

Determines if a table has been extended.
{#r_TU-hasExtensions__table_lby_m1w_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 18. Parameters]

{#r_TU-hasExtensions__table_lby_m1w_4t} {#r_TU-hasExtensions__table_mby_m1w_4t__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the table has extensions. |
[Table 19. Returns]

{#r_TU-hasExtensions__table_mby_m1w_4t}  

    var table = new TableUtils("cmdb_ci_server");
    gs.print(table.hasExtensions());

Output:

    true

## TableUtils - isBaseClass() {#ariaid-title12}

Determines if a table is a base class, meaning it has no parents and has
extensions.
For example, Task is a base class since it is not extended from another table and has
tables extended from it. Sys_user is not a base class because it has no parents, but does
not have extensions.
{#r_TU-isBaseClass__table_k5p_w1w_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 20. Parameters]

{#r_TU-isBaseClass__table_k5p_w1w_4t} {#r_TU-isBaseClass__table_l5p_w1w_4t__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether a table is a base class table meaning it has no parents but has extensions. Valid values: * true: Table is a base class. * false: Table is not a base class. {#r_TU-isBaseClass__ul_wp1_hjt_43b} |
[Table 21. Returns]

{#r_TU-isBaseClass__table_l5p_w1w_4t}  

    var table = new TableUtils("task");
    gs.print("Task is base class: " + table.isBaseClass());
     
    var table = new TableUtils("sys_user");
    gs.print("User is base class: " + table.isBaseClass());

Output:

     Task is base class: true
    User is base class: false

## TableUtils - isSoloClass() {#ariaid-title13}

Determines if the table has no parents and no extensions.
{#r_TU-isSoloClass__table_lv2_nbw_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 22. Parameters]

{#r_TU-isSoloClass__table_lv2_nbw_4t} {#r_TU-isSoloClass__table_mv2_nbw_4t__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the table has no parent and no table is extended from it. |
[Table 23. Returns]

{#r_TU-isSoloClass__table_mv2_nbw_4t}  

    var table = new TableUtils("task");
    gs.print("task is solo class: " + table.isSoloClass());
     
    var table = new TableUtils("cmdb_ci_win_server");
    gs.print("cmdb_ci_win_server is solo class: " + table.isSoloClass());
     
    var table = new TableUtils("sys_user");
    gs.print("sys_user is solo class: " + table.isSoloClass());

Output:

    task is solo class: false
    cmdb_ci_win_server is solo class: false
    sys_user is solo class: true

## TableUtils - tableExists() {#ariaid-title14}

Checks to see if a table exists.
{#r_TU-tableExists__table_txx_x4v_4t__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 24. Parameters]

{#r_TU-tableExists__table_txx_x4v_4t} {#r_TU-tableExists__table_uxx_x4v_4t__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the table exists. |
[Table 25. Returns]

{#r_TU-tableExists__table_uxx_x4v_4t}  

    var table = new TableUtils("my_table");
    gs.print("Does 'my_table' exist? " + table.tableExists());

Output: Does 'my_table' exist? false

