TableUtils - Global

TableUtils is a class of shortcuts for accessing table related information.

The TableUtils class is available to server-side scripts.

TableUtils - drop(String tableName)

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.
Table 1. Parameters
Name Type Description
tableName String Name of the table to drop
Table 2. Returns
Type Description
void

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)

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.
Table 3. Parameters
Name Type Description
tableName String Name of the table to drop
Table 4. Returns
Type Description
void

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)

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.
Table 5. Parameters
Name Type Description
tableName String The table to drop
Table 6. Returns
Type Description
void

var tu = new TableUtils();
tu.dropAndClean("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()

Gets the base table name from which the table was extended.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String The base table name

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

Output: cmdb_ci

TableUtils - getAllExtensions()

Returns the list of tables that extend a table, includes the base table.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
ArrayList A list of tables that extend the table, includes the base table.

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()

Returns a list of all classes participating in the hierarchy of the specified table.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
ArrayList A list of all classes in the specified table's hierarchy.

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()

Get the table hierarchy.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
ArrayList A list of table names in the parent hierarchy.

var table = new TableUtils("incident");
gs.print(table.getTables());

Output: [incident, task]

TableUtils - getTableExtensions()

Gets a list of tables that extend a table.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
ArrayList A list of table names that extend the table.

var table = new TableUtils("task");
gs.print(table.getTableExtensions());
Output:
[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 - hasExtensions()

Determines if a table has been extended.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
Boolean True if the table has extensions.

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

Output: true

TableUtils - isBaseClass()

Determines if a table has no parents and has extensions.

Task is a base class since it is not extended from another table and has tables extended from it, but sys_user is not a base class - it has no parents, but does not have extensions.

Table 19. Parameters
Name Type Description
None
Table 20. Returns
Type Description
void

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()

determines if the table has no parents and no extensions.

Table 21. Parameters
Name Type Description
None
Table 22. Returns
Type Description
Boolean True if the table has no parent and no table is extended from it.

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()

Checks to see if a table exists.

Table 23. Parameters
Name Type Description
None
Table 24. Returns
Type Description
Boolean True if the table exists.

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

Output: Does 'my_table' exist? false

TableUtils - TableUtils(String tableName)

Creates an instance of a TableUtils class.

Table 25. Parameters
Name Type Description
tableName String The table name

var tu = new TableUtils("incident");