问题
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