Name

global.ScrumSprintAbstract

Description

No description available

Script

var ScrumSprintAbstract = Class.create();
ScrumSprintAbstract.prototype = {
  // Can be an array of sysIds too
  initialize: function(sysId) {
  	this.sysId = sysId;
  },
  
  _getCompletedStates: function() {
  	var completedStates = new ScrumStatesUtil('rm_story').getCompletedStates();
  	return completedStates;
  },
  
  _getCancelledStates: function() {
  	var cancelledStates = new ScrumStatesUtil('rm_story').getCancelledStates();
  	return cancelledStates;
  },
  
  completedCount: function() {
  	var completedCount = 0;
  	var completedStates = this._getCompletedStates();
  	
  	var completedStories = new GlideAggregate('rm_story');
  	completedStories.addQuery('state', 'IN', completedStates);
  	completedStories.addQuery('sprint','IN' , this.sysId);
  	completedStories.addAggregate('COUNT');
  	completedStories.query();

  	if (completedStories.next())
  		completedCount = completedStories.getAggregate('COUNT');
  	
  	return completedCount;
  },
  
  cancelledCount: function() {
  	var cancelledCount = 0;
  	var cancelledStates = this._getCancelledStates();

  	var cancelledStories = new GlideAggregate('rm_story');
  	cancelledStories.addQuery('state', 'IN', cancelledStates);
  	cancelledStories.addQuery('sprint','IN' , this.sysId);
  	cancelledStories.addAggregate('COUNT');
  	cancelledStories.query();

  	if (cancelledStories.next())
  		cancelledCount = cancelledStories.getAggregate('COUNT');
  	
  	return cancelledCount;
  },
  
  incompleteCount: function() {
  	var incompleteCount = 0;
  	var completedStates = this._getCompletedStates();
  	var cancelledStates = this._getCancelledStates();
  	
  	var incompleteStories = new GlideAggregate('rm_story');
  	incompleteStories.addQuery('state', 'NOT IN', completedStates.concat(cancelledStates)).addOrCondition('state', 'NULL');
  	incompleteStories.addQuery('sprint', 'IN', this.sysId);
  	incompleteStories.addAggregate('COUNT');
  	incompleteStories.query();

  	if (incompleteStories.next())
  		incompleteCount = incompleteStories.getAggregate('COUNT');
  	
  	return incompleteCount;
  },
  
  moveIncompleteRecordsToSprint: function(newSprint) {
  	var success = true;
  	var completedStates = this._getCompletedStates();
  	var cancelledStates = this._getCancelledStates();
  	
  	var stories = new GlideRecordSecure('rm_story');
  	stories.addQuery('state', 'NOT IN', completedStates.concat(cancelledStates)).addOrCondition('state', 'NULL');		
  	stories.addActiveQuery();
  	stories.addQuery('sprint', 'IN', this.sysId);
  	stories.query();
  	while(stories.next()){
  		stories.setValue('sprint', newSprint);
  		if(!stories.update())
  			success = false;
  	}
  	
  	return success;
  },

  type: 'ScrumSprintAbstract'
};

Sys ID

442d66c193c5330064f572edb67ffbab

Offical Documentation

Official Docs: