Name

global.ScrumStatesUtilAbstract

Description

No description available

Script

var ScrumStatesUtilAbstract = Class.create();
ScrumStatesUtilAbstract.prototype = {
  initialize: function(sysClassName) {
      if (JSUtil.nil(sysClassName))
          return;

      var gr = new GlideRecord(sysClassName);
      gr.initialize();
      this.stateElement = gr.state;
  },

  getCompletedStates: function() {
      var completedAttribute = this.stateElement.getAttribute('completed_states');

      if (typeof completedAttribute === 'string')
          return completedAttribute.split(";");

      return null;
  },

  getCancelledStates: function() {
      var cancelAttribute = this.stateElement.getAttribute('cancelled_states');

      if (typeof cancelAttribute === 'string')
          return cancelAttribute.split(";");

      return null;
  },

  isCompletedState: function(stateVal) {
      var completedStates = this.getCompletedStates();

      if (JSUtil.notNil(completedStates))
          return completedStates.indexOf(stateVal) > -1;

      return false;
  },

  isCancelledState: function(stateVal) {
      var cancelledStates = this.getCancelledStates();

      if (JSUtil.notNil(cancelledStates))
          return cancelledStates.indexOf(stateVal) > -1;

      return false;
  },
  
  isCancelledOrCompletedState: function(stateVal) {
  	return this.isCancelledState(stateVal) || this.isCompletedState(stateVal);
  },

  completeStateToggled: function(currentState, previousState) {
      return this.isCompletedState(currentState) !== this.isCompletedState(previousState);
  },

  cancelStateToggled: function(currentState, previousState) {
      return this.isCancelledState(currentState) !== this.isCancelledState(previousState);
  },

  cancelOrCompleteStateToggled: function(current, previous) {
      var currState = current.getValue('state');
      var prevState = previous.getValue('state');

      return this.cancelStateToggled(currState, prevState) || this.completeStateToggled(currState, prevState);
  },

  stateChangedFromComplete: function(previousState, currentState) {
      return !(this.isCompletedState(currentState)) && this.isCompletedState(previousState);
  },

  stateChangedFromCancelled: function(previousState, currentState) {
      return !(this.isCancelledState(currentState)) && this.isCancelledState(previousState);
  },
  
  stateChangedFromCancelledOrComplete: function(previousState, currentState) {
  	return this.stateChangedFromComplete(previousState, currentState) || this.stateChangedFromCancelled(previousState, currentState);
  },
  
  stateChangedToCancelled: function(previousState, currentState) {
  	return this.isCancelledState(currentState) && !(this.isCancelledState(previousState));
  },

  type: 'ScrumStatesUtilAbstract'
};

Sys ID

676523f35b4810109dac15233381c70a

Offical Documentation

Official Docs: