问题
In the code below I am trying to copy a existing feature, and for that creating a new object as DeepCopy function is not working for me. But formattedId is not getting generated for new feature object
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'
});
});
Please any suggestion, any help on this..
回答1:
Per WS API documentation, PortfolioItem is a non-creatable type. With some modifications, here is your code that creates a feature. Below are two examples.
I replaced portfolioitem
with portfolioitem/feature
in the artifactTypes
of the ChooserDialog in the first example.
The second example allows a choice of pi types, and notice that the type in Rally.data.ModelFactory.getModel
in the second example is set dynamically.
EXAMPLE 1 (only features):
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");
}
}
});
}
});
EXAMPLE 2 (all pi types):
The second example works with all pi types, and artifactTypes
is expanded to include themes, initiative and features:
artifactTypes: ['portfolioitem/theme','portfolioitem/initiative','portfolioitem/feature']
Here is the code:
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");
}
}
});
}
});
来源:https://stackoverflow.com/questions/25845532/formattedid-is-not-getting-generated-for-new-feature-record