TableUtils : global

  • Rversion finale: Yokohama
  • Mis à jour 30 janv. 2025
  • 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)

    Crée une instance d’une classe TableUtils.

    Tableau 1. Paramètres
    Nom Type Description
    tableName Chaîne Le nom de table
    var tu = new TableUtils("incident");

    TableUtils : drop(String tableName)

    Supprime une table de base de données.

    Remarque :
    Utiliser avec une extrême prudence. La suppression d’une table supprime définitivement la table et toutes ses données. Si la table est étendue, utilisez dropTableAndExtensions.
    Tableau 2. Paramètres
    Nom Type Description
    tableName Chaîne Nom de la table à abandonner
    Tableau 3. Renvoie
    Type Description
    nul
    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)

    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.
    Tableau 4. Paramètres
    Nom Type Description
    tableName Chaîne Nom de la table à abandonner
    Tableau 5. Renvoie
    Type Description
    nul
    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)

    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.
    Tableau 6. Paramètres
    Nom Type Description
    tableName Chaîne Table à abandonner
    Tableau 7. Renvoie
    Type Description
    nul
    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()

    Renvoie le nom de la table de base à partir de laquelle la table a été étendue.

    Remarque :
    Pour toute table de la hiérarchie cmdb_ci, cette méthode renvoie cmdb_ci et non la cmdb, qui est la table de base réelle.
    Tableau 8. Paramètres
    Nom Type Description
    Aucun
    Tableau 9. Renvoie
    Type Description
    Chaîne Nom de la table de base
    var table = new TableUtils("cmdb_ci_server");
    gs.print(table.getAbsoluteBase());

    Sortie : cmdb_ci

    TableUtils : getAllExtensions()

    Renvoie la liste des tables qui étendent une table, y compris la table de base.

    Tableau 10. Paramètres
    Nom Type Description
    Aucun
    Tableau 11. Renvoie
    Type Description
    Tableau de liste Une liste de tables qui étendent la table, inclut la table de base.
    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()

    Renvoie une liste de toutes les classes participant à la hiérarchie de la table spécifiée.

    Tableau 12. Paramètres
    Nom Type Description
    Aucun
    Tableau 13. Renvoie
    Type Description
    Tableau de liste Liste de toutes les classes dans la hiérarchie de la table spécifiée.
    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()

    Renvoie la hiérarchie de table.

    Tableau 14. Paramètres
    Nom Type Description
    Aucun
    Tableau 15. Renvoie
    Type Description
    Tableau de liste Liste de noms de tables dans la hiérarchie parente.
    // 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()

    Renvoie une liste des tables qui étendent une table.

    Tableau 16. Paramètres
    Nom Type Description
    Aucun
    Tableau 17. Renvoie
    Type Description
    Tableau de liste Une liste de noms de tables qui étendent la table.

    Cet exemple montre que 58 tables dans cette instance étendent la table Ordinateur [cmdb_ci_computer]. (Résultats condensés 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()

    Détermine si une table a été étendue.

    Tableau 18. Paramètres
    Nom Type Description
    Aucun
    Tableau 19. Renvoie
    Type Description
    Booléen Vrai si la table a des extensions.
    var table = new TableUtils("cmdb_ci_server");
    gs.print(table.hasExtensions());
    Sortie :
    true

    TableUtils : isBaseClass()

    Détermine si une table est une classe de base, ce qui signifie qu’elle n’a aucun parent et qu’elle a des extensions.

    Par exemple, Tâche est une classe de base puisqu’elle n’est pas étendue à partir d’une autre table et qu’elle possède des tables étendues à partir de cette dernière. Sys_user n’est pas une classe de base car elle n’a pas de parents, mais n’a pas d’extensions.

    Tableau 20. Paramètres
    Nom Type Description
    Aucun
    Tableau 21. Renvoie
    Type Description
    Booléen Marqueur qui indique 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 : la table n’est pas une classe de base.
    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()

    Détermine si la table n’a aucun parent ni aucune extension.

    Tableau 22. Paramètres
    Nom Type Description
    Aucun
    Tableau 23. Renvoie
    Type Description
    Booléen Vrai si la table n’a aucun parent et qu’aucune table n’est étendue à partir de celui-ci.
    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()

    Vérifie si une table existe.

    Tableau 24. Paramètres
    Nom Type Description
    Aucun
    Tableau 25. Renvoie
    Type Description
    Booléen Vrai si la table existe.
    var table = new TableUtils("my_table");
    gs.print("Does 'my_table' exist? " + table.tableExists());

    Sortie : « my_table » existe-t-il ? faux