Name

global.CMDBDynamicIREFeatureTable

Description

No description available

Script

var CMDBDynamicIREFeatureTable = Class.create();
CMDBDynamicIREFeatureTable.prototype = {

  // Tables to filter out from the base table cmdb_ci.
  _EXCLUDED_TABLES: ['ecc_event', 'discovery_log', 'cmdb_metric', 'u_eal_submission', 'cmdb_dynamic_ire_match', 'sa_notification'],
  
  _CMDB_CI: 'cmdb_ci',

  initialize: function() {},

  process: function() {
      var map = {};
      var baseTable = this._CMDB_CI;
      var addRef = false;

      // If we are a cmdb_dynamic_ire_filter_condition add extended and ref tables from the current parent table.
      if (!gs.nil(current.model_id)) {
          baseTable = current.model_id.cmdb_class;
          addRef = true;
      }

      // If we are a cmdb_dynamic_ire_feature add extended and ref tables from the current parent table.
      if (!gs.nil(current.filter_condition_id)) {
          baseTable = current.filter_condition_id.cmdb_class;
          addRef = true;
      }

      var tables = j2js(new TableUtils(baseTable).getTables());
      tables = tables.concat(j2js(new TableUtils(baseTable).getTableExtensions()));

      for (var i = 0; i < tables.length; i++) {
          map[tables[i]] = '';
          if (addRef == true) {
              var refTables = this._getReferencingTables(tables[i]);
              for (var j = 0; j < refTables.length; j++)
                  map[refTables[j]] = '';
          }
      }

      var result = [];

      for (var tab in map)
          if (tab != baseTable)
              result.push(tab);

      result = this._filterTable(result);
      return result;
  },

  _filterTable: function(tables) {


      var filtered = [];

      for (var i = 0; i < tables.length; i++) {
          var tbl = tables[i];
          var j = 0;
          while (j < this._EXCLUDED_TABLES.length) {
              if (tbl.indexOf(this._EXCLUDED_TABLES[j]) == 0)
                  break;
              j++;
          }
          // filter out tables meant for workflow
          if (tbl.startsWith('var__'))
              continue;

          if (j == this._EXCLUDED_TABLES.length)
              filtered.push(tbl);
      }
      return filtered;
  },

  _getReferencingTables: function(table) {
      var tables = [];
      var gr = new GlideAggregate('sys_dictionary');
      gr.addQuery('reference', table);
      // exclude entries for duplicate_of field
      gr.addQuery('element', '!=', 'duplicate_of');
      gr.addAggregate('count');
      gr.orderByAggregate('count');
      gr.groupBy('name');
      gr.query();
      while (gr.next())
          tables.push('' + gr.name);

      return tables;
  },

  type: 'CMDBDynamicIREFeatureTable'
};

Sys ID

5bb2aaedc361201099b86a764440dddb

Offical Documentation

Official Docs: