rallyappsdk2lookbackapi

Rally scoping in SnapshotStore


I am trying to get all leaf stories from under my default project in Rally and copy the iteration value of each story (if it exists) to a custom field. Here's my code.

_update_dIteration_for_all_leaves: function(){
    console.log("Working on dIteration for all leaves");

    var me = this;
    var query = Ext.create('Rally.data.lookback.QueryFilter',{property: '_TypeHierarchy', operator: '=', value: "HierarchicalRequirement"});
    query.and(Ext.create('Rally.data.lookback.QueryFilter',{property: 'Children', operator: '=', value: null}));
    query.and(Ext.create('Rally.data.lookback.QueryFilter',{property: '__At', operator: '=', value: 'current'}));
    Ext.create('Rally.data.lookback.SnapshotStore',{
        autoLoad: true,
        context: this.getContext(), 

       // tried context:{workspace: this.getContext().getWorkspace(), project: this.getContext().getProject()} but doesn't work.

        fetch:['Name','FormattedID','Iteration','ObjectID'],
        filters: query,
        listeners: {
            load: function(store,data,success){
                console.log("How many leaf stories? ",data.length);
                var configs = [];
                for(var i=0;i<data.length;i++){
                    if(data[i].data.Iteration!=null && data[i].data.Iteration!=""){
                        console.log('data iteration ', data[i].data.Iteration);
                        configs.push({
                            model: "Iteration",
                            fetch: ['Name','ObjectID'],
                            filters: [{property: 'ObjectID', operator: '=', value: data[i].data.Iteration}],
                            storyid: data[i].data.ObjectID
                        });
                    }
                }
                console.log('configs length ',configs);
                    async.map(configs, me.wsapiQuery, function(err,results){
                //      console.log('len ',results);
                        for(var i=0;i<results.length;i++){
                            //var ObjectID = results[i].get('ObjectID');
                            var name = results[i].get('Name');
                            console.log("Name of iteration "+name+" ID of story "+configs[i].storyid);

                        }

                    });
            }
        },
        scope: this
    });
}

I am not able to add context to this query and not able to get leaf stories only from the current project I am in. Also tried adding Query fiter as:

 {property: '_ProjectHierarchy',operator: 'in', value: this.getContext().getProject().ObjectID}

Although I am not sure if _ProjectHierarchy would be the right way to do it, but it still doesn't work.


Solution

  • Using _ProjectHierarchy will not scope query to a single project, but will scope it to a project and its child projects. Try Lookback API queries directly in the browser to see the difference. For example, in my environment, the first query that uses "_ProjectHierarchy":{"$in":[14020168984]} returns TotalResultCount: 229, but the second query that uses "Project":14020168984 returns TotalResultCount: 128

    https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/14020168894/artifact/snapshot/query.js?find={"_TypeHierarchy":"HierarchicalRequirement","_ProjectHierarchy":{"$in":[14020168984]}}
    
    https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/14020168894/artifact/snapshot/query.js?find={"_TypeHierarchy":"HierarchicalRequirement","Project":14020168984}
    

    You may append &fetch=["Project"] to those queries to see that the second query only returns stories from one project.