I have created a custom kanban board. Inside the board, I have a button on the cards for someone to claim when they are going to code review an item. Upon clicking the button, I wanted to go check the live data to ensure nobody else claimed since the screen was loaded.
I have all that working if its a story, but if its a defect I had an issue. So in reviewing the code, I noticed I did a Rally.data.ModelFactory.getModel then a model.load.
So I am thinking this should be changed to .getModels and change types to incorporate both stories and defect. However, when I do this, how do I get that into the search properly. I am getting stuck with how to load it up and check.
Code snippet is:
if (this.getRecord().get("StoryStatus") == "Review Ready") {
if (this.getRecord().get("CodeReviewedBy") == '') {
content.add([{ xtype: 'button',
text: 'I will review',
scale: 'small',
listeners: {
click: function (btn, e, eOpts) {
// Verify nobody has claimed it yet !
var mod = Rally.data.ModelFactory.getModels({
types: ['HierarchicalRequirement', 'Defect'],
success: function (models) {
var model;
debugger;
if (models.Defect) model = models.Defect
else model = models.HierarchicalRequirement;
model.load(eOpts.scope.record.internalId, {
fetch: ['CodeReviewedBy'],
success: function (currentRecord) {
var currentCRB = currentRecord.get("CodeReviewedBy");
if (currentCRB) {
window.alert('While you were sitting around doing nothing, ' + currentCRB + ' already started reviewing this code');
} else {
var con = Rally.environment.getContext();
currentRecord.set("CodeReviewedBy", con.context.user._refObjectName);
currentRecord.save();
location.reload(true);
//eOpts.scope.refresh();
}
}
});
}
});
this.refresh()
},
scope: this
}
}]);
} else {
content.add([{ xtype: 'label',
html: '<b>Being reviewed by: </b>' + this.getRecord().get("CodeReviewedBy") + '<br>'
}]);
}
}
Once you have the record you can actually use the self property to get the model- that will save you having to use ModelFactory.getModels again.