1

I'm trying to read an OData but I'm getting this error and I don't understand why:

OData error messages

The function which I invoke is the below:

_getHanaData: function() {
  var xsODataModel = new sap.ui.model.odata.v2.ODataModel("/catalog/");
  // ...
},

As shown in the image below, metadata are retrieved and the status of request is 200:

OData service document metadata response

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
M.Morris
  • 147
  • 1
  • 12
  • 3
    Your service is an OData V4 service, try `sap.ui.model.odata.v4.ODataModel`. – Heiko Theißen Oct 18 '21 at 12:29
  • 2
    Also it is more reliable to declare your models in `manifest.json` and access them via `getModel` method of the view. – astentx Oct 18 '21 at 12:41
  • 2
    The OData specification has versions which are not compatible with each other. In your app, you're telling UI5 to fetch V2-compliant OData service document. But what your OData service actually delivers is V4-compliant. – Boghyon Hoffmann Oct 18 '21 at 14:28

1 Answers1

1

As suggest in the comments, the problem is the OData version. I've fixed the issue using sap.ui.model.odata.v4.ODataModel. In the fourth version of OData, the right way to perform CRUD requests is by using bindings. I've found this official tutorial very useful in order to understand how they work.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
M.Morris
  • 147
  • 1
  • 12