如何在 Rally 中创建新的 TimeEntryValue
How to create new TimeEntryValue in Rally
我对 Rally API 和 JS 以及 Whosebug 还很陌生。到目前为止,我一直在使用 Whosebug 来回答我的所有问题,但我似乎找不到任何关于添加新的 TimeEntryValues 的信息。
我正在构建一个允许添加新的 TimeEntryValues 的应用程序。我可以添加或加载 TimeEntryItems,但对于 TimeEntryValues,在浏览器中查看跟踪时,我似乎只 post Hours 字段。
这是一个展示相同问题的简化代码。
launch: function(){
//For this example, pre-define Time Entry Reference, Date, and Hour value
var myTimeEntryItem = "/timeentryitem/1234";
var myDateValue = "2016-05-20T00:00:00.000Z";
var myHours = 2.5;
//Check if Time Entry Value (TEV) already exists
var TEVstore = Ext.create('Rally.data.WsapiDataStore', {
model: 'TimeEntryValue',
fetch: ['ObjectID','TimeEntryItem','Hours','DateVal'],
filters: [{
property: 'TimeEntryItem',
operator: '=',
value: myTimeEntryItem
},
{
property: 'DateVal',
operator: '=',
value: myDateValue
}],
autoLoad: true,
listeners: {
load: function(TEVstore, tevrecords, success) {
//No record found - TEV does not exist
if (tevrecords.length === 0) {
console.log("Creating new TEV record");
Rally.data.ModelFactory.getModel({
type: 'TimeEntryValue',
success: function(tevModel) {
var newTEV = Ext.create(tevModel, {
DateVal: myDateValue,
Hours: myHours,
TimeEntryItem: myTimeEntryItem
});
newTEV.save({
callback: function(result, operation) {
if(operation.wasSuccessful()) {
console.log("Succesful Save");
//Do something here
}
}
});
}
});
} else {
console.log("TEV Record exists.");
//Do something useful here
}
}
},
scope: this
});
}
非常感谢任何提示我做错了什么。
谢谢
这实际上是 App SDK 中长期存在的缺陷,由 WSAPI 属性元数据与用于将数据持久保存到服务器的客户端模型不匹配造成。
基本上发生的事情是 DateVal 和 TimeEntryItem 字段被标记为必需和只读,这没有意义。确实,它们需要在创建时可写,然后是只读。
所以您需要在您的应用程序中做的就是在您尝试保存新的 TimeEntryValue 之前,只需将 DateVal 和 TimeEntryItem 字段标记为可持久化,您就可以开始了。
//workaround
tevModel.getField('DateVal').persist = true;
tevModel.getField('TimeEntryItem').persist = true;
//proceed as usual
var newTEV = Ext.create(tevModel, {
DateVal: myDateValue,
Hours: myHours,
TimeEntryItem: myTimeEntryItem
});
// ...
我对 Rally API 和 JS 以及 Whosebug 还很陌生。到目前为止,我一直在使用 Whosebug 来回答我的所有问题,但我似乎找不到任何关于添加新的 TimeEntryValues 的信息。
我正在构建一个允许添加新的 TimeEntryValues 的应用程序。我可以添加或加载 TimeEntryItems,但对于 TimeEntryValues,在浏览器中查看跟踪时,我似乎只 post Hours 字段。
这是一个展示相同问题的简化代码。
launch: function(){
//For this example, pre-define Time Entry Reference, Date, and Hour value
var myTimeEntryItem = "/timeentryitem/1234";
var myDateValue = "2016-05-20T00:00:00.000Z";
var myHours = 2.5;
//Check if Time Entry Value (TEV) already exists
var TEVstore = Ext.create('Rally.data.WsapiDataStore', {
model: 'TimeEntryValue',
fetch: ['ObjectID','TimeEntryItem','Hours','DateVal'],
filters: [{
property: 'TimeEntryItem',
operator: '=',
value: myTimeEntryItem
},
{
property: 'DateVal',
operator: '=',
value: myDateValue
}],
autoLoad: true,
listeners: {
load: function(TEVstore, tevrecords, success) {
//No record found - TEV does not exist
if (tevrecords.length === 0) {
console.log("Creating new TEV record");
Rally.data.ModelFactory.getModel({
type: 'TimeEntryValue',
success: function(tevModel) {
var newTEV = Ext.create(tevModel, {
DateVal: myDateValue,
Hours: myHours,
TimeEntryItem: myTimeEntryItem
});
newTEV.save({
callback: function(result, operation) {
if(operation.wasSuccessful()) {
console.log("Succesful Save");
//Do something here
}
}
});
}
});
} else {
console.log("TEV Record exists.");
//Do something useful here
}
}
},
scope: this
});
}
非常感谢任何提示我做错了什么。 谢谢
这实际上是 App SDK 中长期存在的缺陷,由 WSAPI 属性元数据与用于将数据持久保存到服务器的客户端模型不匹配造成。
基本上发生的事情是 DateVal 和 TimeEntryItem 字段被标记为必需和只读,这没有意义。确实,它们需要在创建时可写,然后是只读。
所以您需要在您的应用程序中做的就是在您尝试保存新的 TimeEntryValue 之前,只需将 DateVal 和 TimeEntryItem 字段标记为可持久化,您就可以开始了。
//workaround
tevModel.getField('DateVal').persist = true;
tevModel.getField('TimeEntryItem').persist = true;
//proceed as usual
var newTEV = Ext.create(tevModel, {
DateVal: myDateValue,
Hours: myHours,
TimeEntryItem: myTimeEntryItem
});
// ...