Deleting custom classes after migration

This section describes the steps to delete custom classes.

About this task

After the migration from custom classes to the out‑of‑the‑box classes is complete, and if you no longer require the custom classes, you can delete the classes previously used by the IBM Z Resource Discovery application. You may choose to delete these classes manually or by using the provided deletion script.

Important: ServiceNow does not recommend deleting classes using scripts. The recommended approach is to delete custom classes manually through the ServiceNow interface.

Procedure

  1. To delete the custom classes manually, navigate to each corresponding custom class and perform the following steps to delete the records:
    1. In ServiceNow, go to System Definition > Tables.
    2. Search for the required custom class, open the table record, and click Delete in the top‑right corner. When prompted, confirm the deletion.
  2. To delete the custom classes using a script, perform the following steps:
    1. Verify that you are logged in with an Admin role before running the deletion script.
    2. In ServiceNow, search for and open Scripts – Background.
    3. In the Run script (JavaScript executed on server) section, copy and paste the following script. You can modify the script to exclude any custom classes that you do not want to delete.
      (function () {
        try {
          if (typeof TableUtils === "undefined") {
            gs.error(
              "ERROR: TableUtils is not defined\nThis script must be run in GLOBAL scope.\nPlease switch to Global scope and run again.",
            );
            return;
          }
        } catch (e) {
          gs.error(
            "ERROR: Cannot access TableUtils\nThis script must be run in GLOBAL scope.\nError details: " +
              e.message,
          );
          return;
        }
      
        var customClasses = [
          "x_ibmg3_ibm_zsyste_zos_cluster_sysplex",
          "x_ibmg3_ibm_zsyste_zos_db2",
          "x_ibmg3_ibm_zsyste_zos_db2_cluster_data_sharing_group",
          "x_ibmg3_ibm_zsyste_zos_db2_database",
          "x_ibmg3_ibm_zsyste_zos_db2_stored_procedure",
          "x_ibmg3_ibm_zsyste_zos_cics",
          "x_ibmg3_ibm_zsyste_zos_cics_transaction",
          "x_ibmg3_ibm_zsyste_zos_ims",
          "x_ibmg3_ibm_zsyste_zos_ims_database",
          "x_ibmg3_ibm_zsyste_zos_ims_transaction",
          "x_ibmg3_ibm_zsyste_zos_mq",
          "x_ibmg3_ibm_zsyste_zos_mq_queue",
          "x_ibmg3_ibm_zsyste_zos_mq_local_queue",
          "x_ibmg3_ibm_zsyste_zos_mq_remote_queue",
          "x_ibmg3_ibm_zsyste_zos_mq_model_queue",
          "x_ibmg3_ibm_zsyste_zos_mq_alias_queue",
          "x_ibmg3_ibm_zsyste_ibm_program_on_zos",
          "x_ibmg3_ibm_zsyste_temporary_migration_holding_table",
        ];
      
        // Custom table existence check
        function tableExists(tableName) {
          var gr = new GlideRecord("sys_db_object");
          gr.addQuery("name", tableName);
          gr.query();
          return gr.hasNext();
        }
      
        var tu = new TableUtils();
        var deletedCount = 0;
        var skippedCount = 0;
      
        gs.info("=== Starting table cleanup ===");
      
        for (var i = 0; i < customClasses.length; i++) {
          var table = customClasses[i];
      
          if (!tableExists(table)) {
            gs.warn("Table does not exist in sys_db_object: " + table);
            continue;
          }
      
          try {
            var gr = new GlideRecord(table);
            gr.setLimit(1);
            gr.query();
      
            if (gr.hasNext()) {
              gs.info("Skipping - table has data: " + table);
              skippedCount++;
              continue;
            }
      
            gs.info("Dropping table: " + table);
            tu.dropAndClean(table);
            gs.info("Successfully deleted: " + table);
            deletedCount++;
          } catch (e) {
            gs.error("Failed to process table " + table + ": " + e.message);
          }
        }
      
        gs.info(
          "=== Cleanup complete: " +
            deletedCount +
            " deleted, " +
            skippedCount +
            " skipped ===",
        );
      })();
    4. From the In scope list, select Global.
    5. Click Run Script.
    Note: If the CI tables are not successfully migrated, the script will not delete the corresponding custom class.

Results

After execution, the defined custom classes are deleted from the ServiceNow instance.