Name

sn_em_tbac.EvtMgmtTagBasedCmdbKeyUtils

Description

No description available

Script

var EvtMgmtTagBasedCmdbKeyUtils = Class.create();

EvtMgmtTagBasedCmdbKeyUtils.prototype = {
  initialize: function() {
      // cache of CMDB key/values
      this.cmdb_key_values = {};
      this.TABLE = "cmdb_key_value";
      this.CI = "configuration_item";
      this.KEY = "key";
      this.VALUE = "value";
      this.UPDATED = "sys_updated_on";
  },

  /**
   * Gets all the CMDB keys and values from the cmdb_key_value table for the specified CI.
   * @param ci - the sys_id of the CI
   * @returns an object containing key/value pairs, e.g. { "location" : "emea", "manufacturer" : "intel" }
   */
  getCiCmdbKeyValues: function(ci) {
      if (!this.cmdb_key_values[ci]) {
          var keyValues = {};
          var gr = new GlideRecord(this.TABLE);
          gr.addQuery(this.CI, ci);
          gr.orderBy(this.UPDATED); // in case there are multiple values of the same key, we must only use the most recent one.
          gr.query();
          while (gr.next()) {
              keyValues[gr.getValue(this.KEY)] = gr.getValue(this.VALUE);
          }
          this.cmdb_key_values[ci] = keyValues;
      }
      return this.cmdb_key_values[ci];
  },

  type: 'EvtMgmtTagBasedCmdbKeyUtils'
};

Sys ID

6f2c9dc55bc3301009e72b8fb681c74d

Offical Documentation

Official Docs: