Question

I have some code that is pulling a Release model back and displaying in a grid, this is working fine, but I cannot work out how to inspect what is in the returned model.

What I would like is to get the contents of the model in some kind of object that I can reorganise or drill into as I see fit (in this case the release model).

If I add a component and just dump the model into the html it is not returning the contents as I would expect.

Rally.data.ModelFactory.getModel({
        type: 'Release',
        success: function(model) {
                this.add({
                    xtype: 'component',
                    html: model
                });

                this.grid = this.add({
                xtype: 'rallygrid',
                model: model,
                columnCfgs: [
                    'FormattedID',
                    'Name',
                    'RevisionHistory'                    ],
                storeConfig: {
                    filters: queryFilters
                }
            });
        },
        scope: this
    });                 

If I dig into the ExtJS docs it seems I should be able to do something like getData() on the model to return the contents but this is not working.

Inspection in the debugger tells me I have a "Rally.domain.v2.0.project.10098485624.Release" object but I can't see how to simply access the list of items in the object. Obviously there is a way because passing this model to a grid component will display it quite happily. The debugger for this object shows me a number of further functions to call but I have no idea which one or how to use it

...
getArtifactMappings: function () {
getCollectionFields: function () {
getCustomFields: function () {
getField: function (fieldName) {
getFields: function () {
getFieldsByName: function (fieldNames) {
getName: function () {
getNonCollectionFields: function () {
getPermissionLevels: function (permission) {
getProxy: function () {
etc...

The Rally docs indicate I should be able to call getData() on a model https://help.rallydev.com/apps/2.0rc2/doc/#!/api/Rally.data.Model but it looks like the ModelFactory.getModel() is not returning a type that has a getData() method

Was it helpful?

Solution

A model is a class, and a record is an instance of that class.

getData() will work on a record. There are static methods that would work on the actual model, but getData() is not one of them.

Here is a fragment from the code below:

 _onDataLoaded: function(store, data){
      _.each(data, function(record){
         var r = record.getData();
         console.log('release', r);

This code builds a grid of Releases filtered by project and ReleaseStartDate. I noticed that in your code you want to display model information, maybe for debug purposes, by actually modifying the dom. I would prefer to use console.log, but in the example below I did both. I used a border layout with a footer, and set html proprety of the container in the footer to JSON.stringify(r)

  Ext.define('CustomApp', {
     extend: 'Rally.app.App',
     componentCls: 'app',
     layout:'border',
               defaults: {
                  collapsible: true,
                  split: true,
                  bodyStyle: 'padding:15px',
               },
                  items: [{
                      title: 'data',
                      region:'south',
                      itemId: 'd',
                      margins: '5 0 0 0',
                      cmargins: '5 5 0 0'

                  },{
                      title: 'Releases',
                      itemId: 'r',
                      collapsible: false,
                      region:'center',
                      margins: '5 0 0 0'
                  }] ,
      launch: function() {
        var context =  this.getContext();
        var projectId = context.getProject().ObjectID;
        var millisecondsInDay = 86400000;            
                    var currentDate = new Date();
                    var startDate = new Date(currentDate - millisecondsInDay*90); //in the last 90 days
                    var startDateUTC = startDate.toISOString();
         Ext.create('Rally.data.WsapiDataStore', {
            model: 'Release',
            fetch: ['Name','ReleaseStartDate','ReleaseDate', 'State'],
            filters: [
                        {
                        property: 'ReleaseStartDate',
                        operator: '>',
                        value: startDateUTC
                        },
                        {
                        property: 'Project',
                        operator: '=',
                        value: '/project/'+ projectId
                        }
                    ],
            autoLoad: true,
            listeners: {
                load: this._onDataLoaded,
                scope: this
            }
        });
    },


     _onDataLoaded: function(store, data){
     var text = '';
      _.each(data, function(record){
         var r = record.getData();
         console.log('release', r);
         text = text + JSON.stringify(r);
      });
      console.log('text', text);
         this.down('#d').add({
            xtype:'container',
            html: text
            });
         if (!this.down('#g')) {
            this.down('#r').add({
            xtype: 'rallygrid',
            store: store,
            itemId: 'g',
            columnCfgs: [
                {
                   text: 'Name', dataIndex: 'Name'
                },
                {
                   text: 'State', dataIndex: 'State'
                },
                {
                    text: 'Start Date', dataIndex: 'ReleaseStartDate', flex:1
                },
                {
                    text: 'Release Date', dataIndex: 'ReleaseDate',flex:1
                }
            ]

         }); 
         }
         else{
            (this.down('#g')).reconfigure(store);
         }

      }
 });

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top