var dataServiceUrl = "<my service url>";
var oModel = new sap.ui.model.odata.ODataModel(dataServiceUrl);
sap.ui.getCore().setModel(oModel, "AppData");
oObj = {
field1: "one"
field2: "two"
};
oModel.create(
'/collection',
oObj,
null,
function onSuccess(data) {
debugger;
},
function onError(error) {
debugger;
});
The code to create works fine in postman and the object gets created but when it runs in UI5 the collection is returned but the post to create an object does not work. In fact it does not even make the http call to the server.
What appears to happen is when the service queries the backend it gets a list of supported datatypes and as is documented in the XSOData documents in Hana the backend only supports JSON when you have "XSOData exits". The default content type however for datajs is to use ATOM/XML which is thus incompatible and so the client attempts to generate an XML Feed document and crashes with "undefined is not a function".
Fortunatly the fix is quite simple. Change the model's default data type from XML/ATOM to JSON and the problem goes away:
We change this line:
var oModel = new sap.ui.model.odata.ODataModel(dataServiceUrl);
to
var oModel = new sap.ui.model.odata.ODataModel(dataServiceUrl, true /* <<--- This is the important bit */);
and that fixes the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |