---
sourceDocument: Referência de API do Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - pt-BR

ft:publication_title :

    - Referência de API do Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# TableUtils - Global

# TableUtils - Global {#ariaid-title1}

* Versão de lançamento: Xanadu
* 
* Atualizado 1 de ago. de 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 6 min. de leitura

A inclusão de script TableUtils fornece atalhos para acessar informações relacionadas à tabela.

Esta classe está disponível para scripts do lado do servidor.

## TableUtils - TableUtils(cadeia de caracteres "tableName") {#ariaid-title2}

Cria uma instância de uma classe TableUtils.
{#r_TU-TableUtils_S__table_jm5_34v_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| tableName | Cadeia de caracteres | O nome da tabela |
[Tabela 1. Parâmetros]

{#r_TU-TableUtils_S__table_jm5_34v_4t}  

    var tu = new TableUtils("incident");

## TableUtils - drop(cadeia de caracteres "tableName") {#ariaid-title3}

Descarta uma tabela de banco de dados.
Nota:  
Use com extremo cuidado. Descartar uma tabela exclui permanentemente a tabela e todos os seus dados. Se a tabela for estendida, use dropTableAndExtensions.
{#r_TU-drop_S__table_ojq_gpv_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| tableName | Cadeia de caracteres | Nome da tabela a ser descartada |
[Tabela 2. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| vazio |   |
[Tabela 3. Retorna]

{#r_TU-drop_S__table_pjq_gpv_4t}  

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

Saída:

    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(cadeia de caracteres "tableName") {#ariaid-title4}

Descarta uma tabela de banco de dados e limpa as referências à tabela.
Nota:  
Use com extremo cuidado. Descartar uma tabela de banco de dados exclui permanentemente a tabela e todos os seus dados. Se a tabela for estendida, use dropTableAndExtensions.
{#r_TU-dropAndClean_S__table_mb5_15v_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| tableName | Cadeia de caracteres | Nome da tabela a ser descartada |
[Tabela 4. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| vazio |   |
[Tabela 5. Retorna]

{#r_TU-dropAndClean_S__table_nb5_15v_4t}  

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

Saída:

    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(cadeia de caracteres "tableName") {#ariaid-title5}

Descarta uma tabela de banco de dados, todas as suas tabelas estendidas e limpa as referências às tabelas.
Nota:  
Use com extremo cuidado. Descartar uma tabela de banco de dados exclui permanentemente a tabela e todos os seus dados.
{#r_TU-dropTableAndExtensions_S__table_yhf_r5v_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| tableName | Cadeia de caracteres | A tabela a ser descartada |
[Tabela 6. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| vazio |   |
[Tabela 7. Retorna]

{#r_TU-dropTableAndExtensions_S__table_zhf_r5v_4t}  

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

Saída:

    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}

Retorna o nome da tabela base da qual a tabela foi estendida.
Nota:  
Para qualquer tabela na hierarquia cmdb_ci, este método retorna cmdb_ci e não cmdb, que é a tabela base real.
{#r_TU-getAbsoluteBase__table_c3f_gyv_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 8. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Nome da tabela base |
[Tabela 9. Retorna]

{#r_TU-getAbsoluteBase__table_d3f_gyv_4t}  

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

Saída: cmdb_ci

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

Retorna a lista de tabelas que estendem uma tabela, incluindo a tabela base.
{#r_TU-getAllExtensions__table_yq3_gxv_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 10. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| ArrayList | Uma lista de tabelas que estendem a tabela inclui a tabela base. |
[Tabela 11. Retorna]

{#r_TU-getAllExtensions__table_zq3_gxv_4t}  

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

Saída:

    [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}

Retorna uma lista de todas as classes que participam da hierarquia da tabela especificada.
{#r_TU-getHierarchy__table_lbl_ryv_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 12. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| ArrayList | Uma lista de todas as classes na hierarquia da tabela especificada. |
[Tabela 13. Retorna]

{#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}

Retorna a hierarquia da tabela.
{#r_TU-getTables__table_z1t_3wv_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 14. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| ArrayList | Uma lista de nomes de tabelas na hierarquia primária. |
[Tabela 15. Retorna]

{#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++;
    }

Saída:

    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}

Retorna uma lista de tabelas que estendem uma tabela.
{#r_TU-getTableExtensions__table_sfl_twv_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 16. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| ArrayList | Uma lista de nomes de tabelas que estendem a tabela. |
[Tabela 17. Retorna]

{#r_TU-getTableExtensions__table_tfl_twv_4t}  
Este exemplo mostra que 58 tabelas nesta instância estendem a tabela Computador \[cmdb_ci_computer\]. (Saída resumida abaixo.)

    // 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++;
    }

Saída:

    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}

Determina se uma tabela foi estendida.
{#r_TU-hasExtensions__table_lby_m1w_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 18. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Booliano | Verdadeiro se a tabela tiver extensões. |
[Tabela 19. Retorna]

{#r_TU-hasExtensions__table_mby_m1w_4t}  

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

Saída:

    true

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

Determina se uma tabela é uma classe base, o que significa que ela não tem elementos primários e tem extensões.
Por exemplo, Tarefa é uma classe base, pois não é estendida de outra tabela e tem tabelas estendidas dela. Sys_user não é uma classe base porque não tem classes primárias, mas não tem extensões.
{#r_TU-isBaseClass__table_k5p_w1w_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 20. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Booliano | Sinalizador que indica se uma tabela é uma tabela de classe base, o que significa que ela não tem primárias, mas tem extensões. Valores válidos: * verdadeiro: a tabela é uma classe base. * falso: a tabela não é uma classe base. {#r_TU-isBaseClass__ul_wp1_hjt_43b} |
[Tabela 21. Retorna]

{#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());

Saída:

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

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

Determina se a tabela não tem elementos primários nem extensões.
{#r_TU-isSoloClass__table_lv2_nbw_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 22. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Booliano | Verdadeiro se a tabela não tiver pai e nenhuma tabela for estendida a partir dele. |
[Tabela 23. Retorna]

{#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());

Saída:

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

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

Verifica se existe uma tabela.
{#r_TU-tableExists__table_txx_x4v_4t__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 24. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Booliano | Verdadeiro se a tabela existir. |
[Tabela 25. Retorna]

{#r_TU-tableExists__table_uxx_x4v_4t}  

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

Saída: "my_table" existe? falso

