未为新功能记录生成FormattedID

时间:2014-09-15 10:07:14

标签: javascript extjs rally appsdk2

在下面的代码中,我试图复制一个现有的功能,并为此创建一个新对象,因为DeepCopy功能对我不起作用。但是没有为新的特征对象生成formattedId

Rally.onReady(function() {
var newObj = {};
Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    autoScroll: true,
    launch: function() {
        Ext.create('Rally.ui.dialog.ChooserDialog', {
            //model: 'PortfolioItem/Feature',
            //fetch: ['FormattedID','Name','UserStories'],
            width: 450,
            autoScroll: true,
            height: 525,
            title: 'Select to Copy',
            pageSize: 100,
            closable: false,
            selectionButtonText: 'Copy',
            //autoLoad: true,                   
            artifactTypes: ['portfolioitem'],
            autoShow: true,
            listeners: {
                artifactChosen: function(selectedRecord) {
                    newObj = selectedRecord;
                    this.onqModelRetrieved();
                },
                scope: this
            },
            storeConfig : {
                filters: [
                    {
                        property: 'PortfolioItemType.Name',
                        operator: '!=',
                        value: ''
                    }
                ]
            }
        });     
    },
    onqModelRetrieved: function() {
        Rally.data.ModelFactory.getModel({
            type: 'PortfolioItem',
            success: this.onModelRetrieved,
            scope: this
        });     
    },      
    onModelRetrieved: function(model) {
        this.model = model;
        this.createFeature();
    },

    createFeature: function() {
        var record = Ext.create(this.model, {
            Name: "(Copy of) " + newObj.data.Name,
            //State: 'Open',
            Description: newObj.data.Description,
            type: newObj.data.Workspace.type
        });
        record.save;
    }               
});

Rally.launchApp('CustomApp', {
    name: 'Example'
}); 

});

请提出任何建议,对此有任何帮助..

1 个答案:

答案 0 :(得分:1)

根据每个WS API文档,PortfolioItem是一种不可创建的类型。通过一些修改,这是您创建功能的代码。以下是两个例子。

我在第一个示例中的ChooserDialog的portfolioitem中将portfolioitem/feature替换为artifactTypes

第二个示例允许选择pi类型,并注意第二个示例中Rally.data.ModelFactory.getModel中的类型是动态设置的。

示例1(仅限功能):

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    items:{ html:'<a href="https://help.rallydev.com/apps/2.0rc3/doc/">App SDK 2.0rc3 Docs</a>'},
    _newObj : {},
    launch: function() {
        Ext.create('Rally.ui.dialog.ChooserDialog', {
            width: 450,
            autoScroll: true,
            height: 525,
            title: 'Select to Copy',
            pageSize: 100,
            closable: false,
            selectionButtonText: 'Copy',                  
            artifactTypes: ['portfolioitem/feature'],
            autoShow: true,
            listeners: {
                artifactChosen: function(selectedRecord) {
                    console.log(selectedRecord.get('FormattedID') + ', ' + selectedRecord.get('Name') + ' was chosen');
                    this._newObj = selectedRecord;
                    this.onqModelRetrieved();
                },
                scope: this
            },
        }); 
    },
     onqModelRetrieved: function() {
        Rally.data.ModelFactory.getModel({
            type: 'PortfolioItem/Feature',
            success: this.onModelRetrieved,
            scope: this
        });     
    },      
    onModelRetrieved: function(model) {
        this.model = model;
        this.createFeature();
    },

    createFeature: function() {
        var record = Ext.create(this.model, {
            Name: "(Copy of) " + this._newObj.get('Name'),
        });
        record.save({
            callback: function(result, operation) {
                if(operation.wasSuccessful()) {
                    console.log('created feature:', result.get('ObjectID'),result.get('FormattedID'),result.get('Name'));
                }
                else{
                    console.log("error");
                }
            }
        });
    }       
});

enter image description here

示例2(所有pi类型):

第二个示例适用于所有pi类型,artifactTypes已扩展为包含主题,主动性和功能:

artifactTypes: ['portfolioitem/theme','portfolioitem/initiative','portfolioitem/feature']

以下是代码:

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    items:{ html:'<a href="https://help.rallydev.com/apps/2.0rc3/doc/">App SDK 2.0rc3 Docs</a>'},
    _newObj : {},
    _type : null,
    launch: function() {
        Ext.create('Rally.ui.dialog.ChooserDialog', {
            width: 450,
            autoScroll: true,
            height: 525,
            title: 'Select to Copy',
            pageSize: 100,
            closable: false,
            selectionButtonText: 'Copy',                  
            artifactTypes: ['portfolioitem/theme','portfolioitem/initiative','portfolioitem/feature'],
            autoShow: true,
            storeConfig:{
                fetch: ['Name','PortfolioItemTypeName']
            },
            listeners: {
                artifactChosen: function(selectedRecord) {
                    console.log(selectedRecord.get('FormattedID') + ', ' + selectedRecord.get('Name') + ' of type ' + selectedRecord.get('PortfolioItemTypeName') + ' was chosen');
                    this._type = selectedRecord.get('PortfolioItemTypeName');
                    this._newObj = selectedRecord;
                    this.onqModelRetrieved();
                },
                scope: this
            },
        }); 
    },
     onqModelRetrieved: function() {
        var that = this;
        that._type = 'PortfolioItem/' + that._type,
        Rally.data.ModelFactory.getModel({
            type: that._type,
            success: this.onModelRetrieved,
            scope: this
        });     
    },      
    onModelRetrieved: function(model) {
        this.model = model;
        this.createFeature();
    },

    createFeature: function() {
        var record = Ext.create(this.model, {
            Name: "(Copy of) " + this._newObj.get('Name'),
        });
        record.save({
            callback: function(result, operation) {
                if(operation.wasSuccessful()) {
                    console.log('created feature:', result.get('ObjectID'),result.get('FormattedID'),result.get('Name'),result.get('PortfolioItemTypeName'));
                }
                else{
                    console.log("error");
                }
            }
        });
    }       
});