Performing OData methods with Edm.DateTime as part of primary keys

时间:2019-04-08 14:00:52

标签: odata sapui5

I have the problem, that I want to update a table via HTTP-request. But I always get an error-message on the Edm.DateTime attributes in the table.

Error: Invalid URI-Segment '00:00',ValdTo=datetime'2019-04-03T00:00:00')'"}

Even the value is already converted to Edm.DateTime.

valdfrom_edit = encodeURI(sap.ui.model.odata.ODataUtils.formatValue(new Date(values.ValdFrom), "Edm.DateTime"));
var update = "/ZSCORDERINGSet(Mandt='010',Vkorg='" + vkorg_Edit + "',ZzscSpSas='" + suppl_edit + "',ValdFrom=" + valdfrom_edit + ",ValdTo=" + valdto_edit + ")";

1 个答案:

答案 0 :(得分:0)

尝试

const myODataModel = this.getOwnerComponent().getModel(/*modelName*/);
const update = () => myODataModel.update("/" + myODataModel.createKey("ZSCORDERINGSet", {
  //<key>s for ZSCORDERING as described in $metadata
  Mandt: "010",
  Vkorg: vkorg_Edit,
  ZzscSpSas: suppl_edit,
  ValdFrom: new Date(values.ValdFrom), // no need to use ODataUtils.
  ValdTo: valdto_edit
}), {
  // properties of the entry that should be updated
}, {
  // additional parameters such as success-, error-handler, groupId, ...
});
myODataModel.metadataLoaded().then(update);

API reference: v2.ODataModel#update

关于API createKey,请参见How to Create Entity Path Dynamically in UI5?,它将根据OData规范并始终以正确的顺序为您创建实体路径。

除此之外,请记住MockServer doesn't support Edm.DateTime in keys

  

Edm.DateTime键:不支持