---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# TableUtils - Global

# TableUtils - Global {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 6 minutes de lecture

L'include de script TableUtils fournit des raccourcis pour accéder aux informations relatives à la table.

Cette classe est disponible pour les scripts côté serveur.

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

Crée une instance d'une classe TableUtils.
{#r_TU-TableUtils_S__table_jm5_34v_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| tableName | Chaîne | Le nom de table |
[Tableau 1. Paramètres]

{#r_TU-TableUtils_S__table_jm5_34v_4t}  

    var tu = new TableUtils("incident");

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

Supprime une table de base de données.
Remarque :  
À utiliser avec une extrême prudence. Supprimer une table supprime définitivement la table et toutes ses données. Si la table est étendue, utilisez dropTableAndExtensions.
{#r_TU-drop_S__table_ojq_gpv_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| tableName | Chaîne | Nom de la table à abandonner |
[Tableau 2. Paramètres]

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

| Type | Description |
|-|-|
| nul |   |
[Tableau 3. Renvoie]

{#r_TU-drop_S__table_pjq_gpv_4t}  

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

Sortie :

    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}

Supprime une table de base de données et nettoie les références à la table.
Remarque :  
À utiliser avec une extrême prudence. La suppression d'une table de base de données supprime définitivement la table et toutes ses données. Si la table est étendue, utilisez dropTableAndExtensions.
{#r_TU-dropAndClean_S__table_mb5_15v_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| tableName | Chaîne | Nom de la table à abandonner |
[Tableau 4. Paramètres]

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

| Type | Description |
|-|-|
| nul |   |
[Tableau 5. Renvoie]

{#r_TU-dropAndClean_S__table_nb5_15v_4t}  

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

Sortie :

    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}

Supprime une table de base de données, toutes ses tables étendues et nettoie les références aux tables.
Remarque :  
À utiliser avec une extrême prudence. La suppression d'une table de base de données supprime définitivement la table et toutes ses données.
{#r_TU-dropTableAndExtensions_S__table_yhf_r5v_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| tableName | Chaîne | Table à abandonner |
[Tableau 6. Paramètres]

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

| Type | Description |
|-|-|
| nul |   |
[Tableau 7. Renvoie]

{#r_TU-dropTableAndExtensions_S__table_zhf_r5v_4t}  

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

Sortie :

    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}

Renvoie le nom de la table de base à partir de laquelle la table a été étendue.
Remarque :  
Pour n'importe quelle table de la hiérarchie cmdb_ci, cette méthode renvoie cmdb_ci et non cmdb, qui est la table de base réelle.
{#r_TU-getAbsoluteBase__table_c3f_gyv_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 8. Paramètres]

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

| Type | Description |
|-|-|
| Chaîne | Nom de la table de base |
[Tableau 9. Renvoie]

{#r_TU-getAbsoluteBase__table_d3f_gyv_4t}  

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

Sortie : cmdb_ci

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

Renvoie la liste des tables qui étendent une table, y compris la table de base.
{#r_TU-getAllExtensions__table_yq3_gxv_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 10. Paramètres]

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

| Type | Description |
|-|-|
| TableauListe | Liste des tables qui étendent la table, y compris la table de base. |
[Tableau 11. Renvoie]

{#r_TU-getAllExtensions__table_zq3_gxv_4t}  

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

Sortie :

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

Renvoie une liste de toutes les classes participant à la hiérarchie de la table spécifiée.
{#r_TU-getHierarchy__table_lbl_ryv_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 12. Paramètres]

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

| Type | Description |
|-|-|
| TableauListe | Une liste de toutes les classes dans la hiérarchie de la table spécifiée. |
[Tableau 13. Renvoie]

{#r_TU-getHierarchy__table_mbl_ryv_4t}  

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

Sortie : \[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}

Renvoie la hiérarchie de table.
{#r_TU-getTables__table_z1t_3wv_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 14. Paramètres]

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

| Type | Description |
|-|-|
| TableauListe | Liste de noms de tables de la hiérarchie parente. |
[Tableau 15. Renvoie]

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

Sortie :

    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}

Renvoie une liste de tables qui étendent une table.
{#r_TU-getTableExtensions__table_sfl_twv_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 16. Paramètres]

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

| Type | Description |
|-|-|
| TableauListe | Une liste de noms de table qui étendent la table. |
[Tableau 17. Renvoie]

{#r_TU-getTableExtensions__table_tfl_twv_4t}  
Cet exemple montre que 58 tables dans cette instance étendent la table Ordinateur \[cmdb_ci_computer\]. (Résultat condensé ci-dessous.)

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

Sortie :

    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}

Détermine si une table a été étendue.
{#r_TU-hasExtensions__table_lby_m1w_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 18. Paramètres]

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

| Type | Description |
|-|-|
| Booléen | Vrai si la table a des extensions. |
[Tableau 19. Renvoie]

{#r_TU-hasExtensions__table_mby_m1w_4t}  

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

Sortie :

    true

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

Détermine si une table est une classe de base, c'est-à-dire qu'elle n'a pas de parents et qu'elle a des extensions.
Par exemple, Tâche est une classe de base, car elle n'est pas étendue à partir d'une autre table et a des tables étendues à partir de celle-ci. Sys_user n'est pas une classe de base, car elle n'a pas de parents, mais n'a pas d'extensions.
{#r_TU-isBaseClass__table_k5p_w1w_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 20. Paramètres]

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

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant si une table est une table de classe de base, ce qui signifie qu'elle n'a pas de parents mais a des extensions. Valeurs valides : * true : la table est une classe de base. * false : table n'est pas une classe de base. {#r_TU-isBaseClass__ul_wp1_hjt_43b} |
[Tableau 21. Renvoie]

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

Sortie :

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

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

Détermine si la table n'a pas de parents ni d'extensions.
{#r_TU-isSoloClass__table_lv2_nbw_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 22. Paramètres]

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

| Type | Description |
|-|-|
| Booléen | Vrai si la table n'a pas de parent et qu'aucune table n'est étendue à partir de celui-ci. |
[Tableau 23. Renvoie]

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

Sortie :

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

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

Vérifie si une table existe.
{#r_TU-tableExists__table_txx_x4v_4t__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 24. Paramètres]

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

| Type | Description |
|-|-|
| Booléen | Vrai si la table existe. |
[Tableau 25. Renvoie]

{#r_TU-tableExists__table_uxx_x4v_4t}  

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

Sortie : \<\< my_table \>\> existe-t-il ? faux

