rallyappsdk2

Rally - More efficient way to get item by ID


I have been trying to query Rally just to get a certain object by its ObjectID, but then I end up needing its parent in many cases. For example, for a task, I need its associated User Story, and that Story's Feature. It ended up being quite the cascade of callbacks (fair warning, it's ugly) - can anyone recommend a more efficient solution? The ability to query by OID is nice, but its too bad I need more than just information about that OID. (Note - solution must utilize WSAPI, not LBAPI).

    Rally.data.WsapiModelFactory.getModel({
        type: 'Task',
        context: {
            workspace: Rally.util.Ref.getRelativeUri()
        },
        success: function(taskModel) {
            taskModel.load(oid, {
                scope: this,
                callback: function(taskRecord, op, success) {
                    if (taskRecord && taskRecord.data.WorkProduct && taskRecord.data.WorkProduct._type == "HierarchicalRequirement") {


                        // get User Story
                        Rally.data.WsapiModelFactory.getModel({
                            type: 'User Story',
                            context: {
                                workspace: Rally.util.Ref.getRelativeUri()
                            },
                            success: function(userStoryModel) {
                                userStoryModel.load(taskRecord.data.WorkProduct._ref, {
                                    scope: this,
                                    callback: function(storyRecord, op, success) {

                                        if (storyRecord && storyRecord.data && storyRecord.data.Feature) {

                                            // Get Feature
                                            Rally.data.WsapiModelFactory.getModel({
                                                type: 'PortfolioItem/Feature',
                                                context: {
                                                    workspace: Rally.util.Ref.getRelativeUri()
                                                },
                                                success: function(featureModel) {
                                                    featureModel.load(storyRecord.data.Feature._ref, {
                                                        scope: this,
                                                        callback: function(featureRecord) {
                                                            displayTask(oid, taskRecord, storyRecord, featureRecord);
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        });
                    }
                }
            });
        }
    });

Solution

  • You can pull in the Work Product parent and its associated Feature directly in a single query. Try this:

        Ext.create('Rally.data.WsapiDataStore', {
            model   : 'Task',
            fetch   : ['WorkProduct','Name','Feature'],
            filters : [{
                property : 'ObjectID',
                value    : OID
            }]
        }).load({
            callback : function(records, operation, success) {
                var task      = records[0];
                var userStory = task.get('WorkProduct');
                var feature   = userStory.Feature;
            }
        });