Question

I would like to retrieve the JSON object for the revision log using the URL associated with the User Story. I have accomplished this with jQuery using the following code, although I would rather do it with built in tools in the Rally SDK. I haven't had any luck with Ext.Ajax or Ext.data.JsonP requests, although I feel that is the correct approach. Any help would be appreciated.

$.ajax({
    url: URL,
    dataType: 'jsonp',
    jsonp: 'jsonp',
    success: function(response) {
        $.each(response.RevisionHistory.Revisions, function(key, rev) {
            //Parse Revision Log
        });
    }
});
Was it helpful?

Solution

This is relatively straightforward with the App SDK 2.0. The following examples in the documentation should be helpful to you:

http://developer.rallydev.com/apps/2.0p4/doc/#!/guide/appsdk_20_data_models

http://developer.rallydev.com/apps/2.0p4/doc/#!/guide/appsdk_20_data_stores

Here's a quick little code snippet to get the revision history of a specific story:

Rally.data.ModelFactory.getModel({
    type: 'UserStory',
    success: function(storyModel) {
        var storyRef = 'https://rally1.rallydev.com/slm/webservice/1.37/hierarchicalrequirement/12345.js';
        var storyID = Rally.util.Ref.getOidFromRef(storyRef);
        storyModel.load(storyID, {
            fetch: ['Name', 'FormattedID', 'Description', 'RevisionHistory', 'Revisions'],
            callback: function(story, operation) {
                if(story && story.get('RevisionHistory') && story.get('RevisionHistory').Revisions) {
                    Ext.Array.each(story.get('RevisionHistory').Revisions, function(revision) {
                        //Parse revision log
                    });
                }
            }
        });
    }
});

The nice thing with using the SDK is that it will automatically do ajax vs. jsonp requests depending on how you are running the app. The example above works great for a single story. If you would like to parse through multiple stories you'd want to use a store instead of model.load:

Ext.create('Rally.data.WsapiDataStore', {
    model: 'UserStory',
    autoLoad: true,
    fetch: ['Name', 'FormattedID', 'Description', 'RevisionHistory', 'Revisions'],    
    listeners: {
        load: function(store, stories) {
            Ext.Array.each(stories, function(story) { 
                if(story && story.get('RevisionHistory') && story.get('RevisionHistory').Revisions) {
                    Ext.Array.each(story.get('RevisionHistory').Revisions, function(revision) {
                        //Parse revision log
                    });
                }
            });
        }
    } 
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top