Agile Central - SDK: How can we build a grid that will list our subscription's workspaces?

Document ID : KB000118589
Last Modified Date : 26/10/2018
Show Technical Document Details
Question:

Trying to build an app that will list all our subscription's workspaces in a grid. Here is my code. It's not working, it's only returning my default workspace.

Why? Can we fix it?
 

_getworkSpaces : function (){
// Get workspaces
Ext.create('Rally.data.wsapi.Store', {
   model: 'Workspace',
   autoLoad: true,
   limit: Infinity,
   sorters: [
      { property: 'Name',direction: 'ASC' }
   ], 
   scope: app,
   filters: [
      {
         property: 'State',
         operator: '=',
         value: 'Open'
      }
   ],
   listeners: {
      load: function(store, data, success) {

         console.log(data);

    }
   },
      fetch: ['Name','State']
   }); 
}

Answer:
The problem with your code is the use of the 'Workspace' model (see the bolded line in the question code excerpt).
Refer to this article to learn the limitation of the 'Workspace' model. Instead you should use the 'Subscription' model, then create a store out of its Workspaces collection.

Here is the full SDK code:


//API Docs: https://help.rallydev.com/apps/2.1/doc/
Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    app: null,

    _whoIsThis: function(aFunctionaName, anObject) {
          console.log('Who Is This: Called by: ', aFunctionaName, ': This = ' , anObject);
    },    

    launch: function() {
        console.log('Worspaces - Start');

        // app = this;
        // this._whoIsThis('launch', this);
        this._loadData();
    },

    // Get data from Rally
    _loadData: function() {

        Ext.create('Rally.data.wsapi.Store', {
            model: 'Subscription',
            fetch: ['Name', 'Workspaces'],
            pageSize: 500,
            autoLoad: true,
            listeners: {
                load: function(store, records) {
                    var subscription = records[0];
                    console.log('subscription.Name = ' + subscription.get('Name'));
                    var WorkspacesCollection = subscription.get('Workspaces');
                    console.log('WorkspacesCollection = ' + WorkspacesCollection);
                    var WorkspaceCount = WorkspacesCollection.Count;
                    console.log('WorkspaceCount = ' + WorkspaceCount);

                    var collectionStore = subscription.getCollection('Workspaces', {
                        fetch: ['Name', 'State'],
                        // autoLoad: true
                    });

                    this._loadGrid(collectionStore);
                    
                    // .load({
                    //     callback: function(records, operation, success) {
                    //         Ext.Array.each(records, function(workspace) {
                    //             console.log(workspace.get('Name') + ': ' + workspace.get('State'));
                    //         });

                    //         app._loadGrid(records);
                    //     }                        

                    // });
                    

                },
                scope: this
            }
        });                    
    },
    
    _loadGrid: function(aStore) {
        this.add({
            xtype: 'rallygrid',
            store: aStore,
            columnCfgs: ['Name', 'State'],
            enableEditing: false
        });
    }
});    
Additional Information:
See this article for a full explanation on the limitation of the Workspace endpoint.