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

ぃ、小莉子 提交于 2019-12-24 13:33:45

问题


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:


Try with

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

About the API createKey, see How to Create Entity Path Dynamically in UI5? It will create the entity path for you according to the OData specification and always in the right order.

Apart from that, please keep in mind that MockServer doesn't support Edm.DateTime in keys.

Edm.DateTime keys: Unsupported



来源:https://stackoverflow.com/questions/55575224/performing-odata-methods-with-edm-datetime-as-part-of-primary-keys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!