Rally defects by portfolio item using SDK

590 Views Asked by At

Does anyone know a way to pull all defects related to an epic using sdk 2? All of our portfolio items are assigned to one root, and our dev teams to another. There is linkage from one side to another via user story parent, but I haven't found a way to see all defects related to a particular epic. suggestions?

1

There are 1 best solutions below

0
On

There are different ways of getting defects that indirectly associated with portfolioitem/feature. Here is one example, where a feature store is created and filtered by current release, and then, using promises, it loads features, then related epic stories, then related child stories, then related defects, and finally builds a grid of defects grouped by Requirement:

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    launch: function() {
        var that = this;
        var today = new Date().toISOString();
        var features = Ext.create('Rally.data.wsapi.Store', {
            model: 'PortfolioItem/Feature',
            fetch: ['UserStories'],
            filters: [
                {
                    property: 'Release.StartDate',
                    operator: '<=',
                    value: today
                },
                {
                    property: 'Release.ReleaseDate',
                    operator: '>=',
                    value: today
                }
            ]
        });
        features.load().then({
            success: this.loadStories,
            scope: this
        }).then({
            success: this.loadChildStories,
            scope: this
        }).then({
            success: this.loadDefects,
            scope: this
        }).then({
            success:function(results) {
                that.makeGrid(results);
            },
            failure: function(){
                console.log("oh noes!")
            }
        });
    },

    loadStories: function(features){
        console.log("features",features)
        var promises = [];
        _.each(features, function(feature){
            var stories = feature.get('UserStories');
            if (stories.Count > 0) {
                stories.store = feature.getCollection('UserStories',{fetch:['Name','FormattedID','Children','Defects','Feature']});
                promises.push(stories.store.load());
            }
        });
        return Deft.Promise.all(promises);
    },

    loadChildStories: function(stories){
        stories = _.flatten(stories);
        console.log("stories",stories);
        var promises = [];
         _.each(stories, function(story){
            var childStories = story.get('Children');
            if (childStories.Count > 0) {
                childStories.store = story.getCollection('Children',{fetch:['Name','ObjectID','FormattedID','Defects']});
                promises.push(childStories.store.load());
            }
        });
        return Deft.Promise.all(promises);
    },

    loadDefects: function(childStories){
        childStories = _.flatten(childStories);
        console.log("childStories",childStories);
        var promises = [];
         _.each(childStories, function(story){
            var defects = story.get('Defects');
            if (defects.Count > 0) {
                defects.store = story.getCollection('Defects',{fetch:['Name','ObjectID','FormattedID','Requirement','State']});
                promises.push(defects.store.load());
            }
        });
        return Deft.Promise.all(promises);
    },

    makeGrid: function(defects){
        defects = _.flatten(defects);
        console.log('defects', defects);
        var data = [];
        _.each(defects, function(defect){
            data.push(defect.data);
        });


        _.each(data, function(record){
            record.defectsParent = record.Requirement.FormattedID + " " + record.Requirement.Name;
        });
        this.add({
            xtype: 'rallygrid',
            showPagingToolbar: true,
            showRowActionsColumn: true,
            editable: false,
            store: Ext.create('Rally.data.custom.Store', {
                data: data,
                groupField: 'defectsParent',
            }),
            features: [{ftype:'groupingsummary'}],
            columnCfgs: [
                {
                    xtype: 'templatecolumn',text: 'ID',dataIndex: 'FormattedID',width: 100,
                    tpl: Ext.create('Rally.ui.renderer.template.FormattedIDTemplate')
                },
                {
                    text: 'Name',dataIndex: 'Name',
                },
                {
                    text: 'Story',dataIndex: 'Requirement',
                    renderer: function(val, meta, record) {
                        return '<a href="https://rally1.rallydev.com/#/detail/userstory/' + record.get('Requirement').ObjectID + '" target="_blank">' + record.get('Requirement').FormattedID + '</a>';
                    }
                },
            ]
        });
    }
});