Name
global.ScrumPlanningBoard
Description
ScrumPlanningBoard - Provides methods to control the setup of the Scrum Planning Board.
Script
/**
* ScrumPlanningBoard
* Provides methods to control the setup of the Scrum Planning Board.
*
* @Author Chris Henson <chris.henson@service-now.com>
*/
var ScrumPlanningBoard = Class.create();
ScrumPlanningBoard.prototype = {
initialize: function(_gs) {
this._log = new GSLog("com.snc.sdlc.scrum.pp.log",this.type).setLog4J();
//this._log.setLevel(GSLog.DEBUG);
// Default this._gs to the global if one isn't passed in.
this._gs = (JSUtil.notNil(_gs) ? _gs : gs);
},
/**
* getLeftParent(releaseId): Returns the parent of the left pane
*
* releaseId: The sysId of the release being used.
*
* returns: String formatted in the following way: table_name:sys_id:backlog_only
* NB backlog_only = true/false as string.
*
* This defaults to the first product in the release for the backlog
*/
getLeftParent: function(releaseId) {
// Try the property to see if there's anything there.
var leftParent = this._gs.getUser().getPreference("com.snc.sdlc.scrum.pp.planning.left_parent");
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getLeftParent] Preference com.snc.sdlc.scrum.pp.planning.left_parent contains: " + leftParent);
//If the user has something set, check that it's OK for the release
if (JSUtil.notNil(leftParent)) {
var comps = leftParent.split(":");
if (comps[0] == "rm_sprint" && JSUtil.notNil(comps[1])) {
var sprnt = new GlideRecord("rm_sprint");
sprnt.addQuery("sys_id","=",comps[1]);
sprnt.addQuery("release","=",releaseId);
sprnt.query();
if (sprnt.getRowCount() != 1) {
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getLeftParent] Invalid Sprint <"+ comps[1] +">");
leftParent = "";
}
}
else if (comps[0] == "cmdb_model" && JSUtil.notNil(comps[1])) {
var m2m = new GlideRecord("m2m_product_release");
m2m.addQuery("model","=",comps[1]);
m2m.addQuery("release","=",releaseId);
m2m.query();
//If it's not a relevant product, blank out
if (m2m.getRowCount() != 1) {
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getLeftParent] Invalid Product <" + comps[1] + ">");
leftParent = "";
}
}
else if (comps[0] == "rm_release_scrum" && JSUtil.notNil(comps[1])) {
// Check that the release id here and the release ID provided are the same.
if (releaseId != comps[1]) {
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getLeftParent] Invalid Release <" + comps[0] + ">");
leftParent = "";
}
}
else {
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getLeftParent] Bad data <" + leftParent + ">");
leftParent = "";
}
}
// Default to the product if the user doesn't have anything set or it was invalid.
if (JSUtil.nil(leftParent)) {
var m2mGr = new GlideRecord("m2m_product_release");
m2mGr.addQuery("release",releaseId);
m2mGr.query();
if (m2mGr.next()) {
if (m2mGr.model) {
this._log.debug("[getLeftParent] Using default");
leftParent = "cmdb_model:" + m2mGr.getValue('model') + ":true";
this._gs.getUser().setPreference("com.snc.sdlc.scrum.pp.planning.left_parent",leftParent);
}
} else {
leftParent = "rm_release_scrum:" + releaseId + ":true";
}
}
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getLeftParent] Returning " + leftParent);
return leftParent;
},
/**
* getRightParent(releaseId,sprintId,leftParent): Returns the parent of the right plane
*
* releaseId: The sys_id of the release beign used
* sprintId: The sys_id of the sprint to use
* leftParent: The id of the left pane parent
*
* returns: String formatted in the following way: table_name:sys_id:backlog_only
* NB backlog_only = true/false as string.
*/
getRightParent: function(releaseId,sprintId,leftParent) {
// The right hand pane is based on the contents of the left hand pane and a sprint id (if passed in).
var leftComps = leftParent.split(":");
//Check if we have a sprint passed in as this is the basis for the right pane
if (sprintId != "")
this._gs.getUser().setPreference("com.snc.sdlc.scrum.pp.planning.right_parent","rm_sprint:" + sprintId + ":true");
var rightParent = this._gs.getUser().getPreference("com.snc.sdlc.scrum.pp.planning.right_parent");
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getRightParent] Preference com.snc.sdlc.scrum.pp.planning.right_parent contains: " + rightParent);
if (JSUtil.notNil(rightParent)) {
var rightComps = rightParent.split(":");
if (rightComps[0] == "rm_sprint" || rightComps[0] == "rm_release_scrum") {
// If it's a sprint on the left, it can only be a sprint on the right.
if (leftComps[0] == "rm_sprint" && rightComps[0] != "rm_sprint") {
if(this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getRightParent] Bad data <" + rightParent + ">");
rightParent = leftParent;
this._gs.getUser().setPreference("com.snc.sdlc.scrum.pp.planning.right_parent",rightParent);
}
else if(leftComps[0] == "rm_sprint" && rightComps[0] == "rm_sprint") {
//Check that the springs are in the same release
var spnt = new GlideRecord("rm_sprint");
spnt.addQuery("sys_id","=",rightComps[1]);
spnt.addQuery("release","=",releaseId);
spnt.query();
if (spnt.getRowCount() != 1) {
if(this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getRightParent] Invalid Sprint <" + rightComps[1] + ">");
rightParent = leftParent;
this._gs.getUser().setPreference("com.snc.sdlc.scrum.pp.planning.right_parent",rightParent);
}
}
}
else {
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getRightParent] Bad data <" + rightParent + ">");
rightParent = "";
}
}
// This should display the release backlog as default.
if (JSUtil.nil(rightParent)) {
this._log.debug("[getRightParent] Using default");
rightParent = "rm_release_scrum:${sysparm_release_id}:true";
this._gs.getUser().setPreference("com.snc.sdlc.scrum.pp.planning.right_parent",rightParent);
}
if (this._log.atLevel(GSLog.DEBUG))
this._log.debug("[getRightParent] Returning " + rightParent);
return rightParent;
},
/**
* getDisplayName(id): Takes in a parent id in the format
*
* id: The id of the record in the format table_name:sys_id:backlog_only
*
* returns: the display value associated to the record
*/
getDisplayName: function(id) {
var displayName = "";
var comps = id.split(":");
var gr = new GlideRecord(comps[0]);
if (gr.get(comps[1])) {
if (comps[0] == "cmdb_model")
displayName = gr.name + "";
else
displayName = gr.short_description + "";
}
if (this._log.atLevel(GSLog.DEBUG)) {
this._log.debug("[getDisplayName] Got id <" + id + ">");
this._log.debug("[getDisplayName] Returning '" + displayName + "'");
}
return displayName;
},
type: 'ScrumPlanningBoard'
};
Sys ID
e865b413c30130003d2ae219cdba8f23