Rally App2.0 - Retrieve a specific story
-
25-06-2021 - |
Question
I am getting the hang of 2.0, but a bit stuck on something that seems simple.
Basically, I have created a new app for my team to use (thanks all for the help). I thought it would be cool to have a way I could add messages to the dashboard.
I decided the easiest way to accomplish this, is to create a story and in my code simply query that one story, grab the description and show it in the app. Sounds easy enough right?
I am having a bit of a time simple running out grabbing the Description field and showing it. I know it sounds odd, but it seems so complicated. I have tried this way
showMessage: function (message) {
debugger;
this.add({
xtype: 'label',
html: message
});
},
getMessage: function () {
var defectStore = Ext.create('Rally.data.WsapiDataStore', {
model: 'UserStory',
fetch: ['Description'],
filters: [{
property: 'FormattedID',
operator: '=',
value: 'US13258'
}],
autoLoad: true,
listeners: {
load: function (store, records) {
debugger;
if (records)
return records[0].get("Description");
}
}
});
},
But seems to get caught up in event spaghetti. Surely there is an easier way :)
Just want to go grab a specific stories description field...
La solution
You can use a model's load method to do this:
var storyOid = 12345;
//Get the story model
Rally.data.ModelFactory.getModel({
type: 'UserStory',
success: function(model) {
//Load the specific story
model.load(storyOid, {
fetch: ['Description']
success: function(record) {
//success!
var description = record.get('Description');
}
});
}
});
Autres conseils
I'm not sure why you're trying to do it with a listener, but I would just call load and get the result upon success, like so:
getMessage: function (storyID) {
var defectStore = Ext.create('Rally.data.WsapiDataStore', {
model: 'UserStory',
fetch: ['Description'],
filters: [{
property: 'FormattedID',
operator: '=',
value: storyID
}],
autoLoad: true
});
defectStore.load({scope: this, callback: function(records, operation, success) {
if(success){
console.log(records[0].get('Description')); // additional logic here
} else {
console.log('You ruined the store. Jerk.');
}
}});
}
I'm thinking you might have some issues, though, unless call showMessage after you check for success, as extJS operates asynchronously.