Name

sn_install_base.InstallBaseStateUtilSNC

Description

This contains helper functions to keep Install Base Item table State and Active fields in sync Can be called by any server script to determine inactive states, default work, or default close states for a given table Configurations are defined in the sn_install_base_item.state dictionary element, usually using dictionary overrides since state values vary per extended table.

Script

var InstallBaseStateUtilSNC = Class.create();
InstallBaseStateUtilSNC.prototype = {
  ATTR_INACTIVE_STATES: "close_states",
  ATTR_DEFAULT_WORK: "default_work_state",
  ATTR_DEFAULT_CLOSE: "default_close_state",

  SYSTEM_DEFAULT_CLOSE: "inactive",
  SYSTEM_DEFAULT_WORK: "in_use",
  SYSTEM_INACTIVE_STATES: ["inactive"],

  /*
   * Init
   * called by new InstallBaseStateUtil(gr)
   * @param Install Base Item GlideRecord
   */
  initialize: function( /*GlideRecord*/ installBaseItemGr) {

      this.installBaseItem = installBaseItemGr;

      if (!installBaseItemGr || !installBaseItemGr.isValidRecord()) {
          if (!installBaseItemGr.isNewRecord()) return;
      }

      this.stateElement = installBaseItemGr.getElement('state');

      this._getTableStates();
      this._getDefaultWork();
      this._getDefaultClose();

  },

  /*
   * Get the active status of a given state
   * @param state value of the state field choice
   * @return boolean true if state is an Inactive state
   */
  isStateInactive: function(state) {
      state = state + "";
      var arrUtil = new global.ArrayUtil();
      if (arrUtil.contains(this.inactiveStates, state))
          return true;
      return false;
  },

  /*
   * Get the value for the default work state, defaults to "in_use" if not specified
   * @return int
   */
  getDefaultWorkState: function() {
      return this.defaultWork;
  },

  /*
   * Get the value for the default close state, defaults to "inactive" if not specified
   * @return int
   */
  getDefaultCloseState: function() {
      return this.defaultClose;
  },

  /*
   * Get the list of inactive state values
   * @return array
   */
  getInactiveStates: function() {
      return this.inactiveStates;
  },

  /*
   * private methods used during init
   */
  _getTableStates: function() {
      var states = this.stateElement.getAttribute(this.ATTR_INACTIVE_STATES);
      if (states)
          this.inactiveStates = states.split(";");
      else
          this.inactiveStates = this.SYSTEM_INACTIVE_STATES;
  },

  _getDefaultWork: function() {
      var value = this.stateElement.getAttribute(this.ATTR_DEFAULT_WORK);
      if (value)
          this.defaultWork = value;
      else
          this.defaultWork = this.SYSTEM_DEFAULT_WORK;
  },

  _getDefaultClose: function() {
      var value = this.stateElement.getAttribute(this.ATTR_DEFAULT_CLOSE);
      if (value)
          this.defaultClose = value;
      else
          this.defaultClose = this.SYSTEM_DEFAULT_CLOSE;
  },

  type: 'InstallBaseStateUtilSNC'
};

Sys ID

a464b375530e1110539dddeeff7b122f

Offical Documentation

Official Docs: