-3

I have to pass two filter parameters to ODATA service. I am trying it as follows:

new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/Z_FI_PAY_D_SRV/PdetailSet?$filter=Laufi eq '"+spayid+"' and Laufd eq '"+spaydt+"'?$sap-client=100",

It is giving following error. GET http://localhost:63655/Payment1/proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/Z_FI_PAY_D_SRV/PdetailSet/$metadata?$filter=Laufi%20eq%20%27U2-28%27 400 (Bad Request) Log-dbg.js:456 2020-07-21 16:40:39.956774 [ODataMetadata] initial loading of metadata failed -

Can anyone suggest correct way to add filter parameters on ODATA service. Thanks.

Philipp
  • 67,764
  • 9
  • 118
  • 153
Ahmed
  • 33
  • 6
  • 1
    Hi, you cannot create a ODataModel Object that way. You need to create the ODataModel with the Base-URL of the service. – Michael Schönbauer Jul 21 '20 at 12:07
  • 1
    From this question and your [previous](https://stackoverflow.com/questions/62949276/how-to-call-odata-service-with-parameters-or-how-to-filter-odata-service) [two](https://stackoverflow.com/questions/62912035/passing-filters-in-odata-service-sap-ui5-to-abap) it appears that you might have to familiarize yourself with how context bindings work in SAPUI5. I would recommend that you try to understand this before asking even more questions about small variations of the very same problem which won't fix your underlying problem because your whole approach is wrong. – Philipp Jul 21 '20 at 13:09
  • Does this answer your question? [Filter with "OR" And "AND" Conditions on Multiple Fields](https://stackoverflow.com/questions/42433200/filter-with-or-and-and-conditions-on-multiple-fields) – Boghyon Hoffmann Jul 21 '20 at 15:57
  • If it's still about displaying data on a detail page, see https://stackoverflow.com/a/48870579/5846045. Adding a Filter is a wrong approach in this case. – Boghyon Hoffmann Jul 21 '20 at 17:54

1 Answers1

1

When you create a new OData model, then you can not provide any filters. You have to provide the base URI of the service.

Filtering by value happens automatically by the UI5 framework based on a context binding.

  1. You create an OData model with new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/Z_FI_PAY_D_SRV/") (or even better: you define your model using your manifest.json).
  2. You assign your model to your view with view.setModel
  3. Then you create property bindings on controls of your view (which you would usually do in the XML definition, but you can also do it in code)
  4. You bind an element on your view. This is where the filtering happens. The UI5 framework looks at the binding path you provided to controlWhichShowsTheThing.bindObject and will perform an HTTP request to the OData model to retrieve that object when required.

Now you might ask "OK, so how does that binding path look"? This actually depends on the oData model itself and how it addresses individual objects.

Philipp
  • 67,764
  • 9
  • 118
  • 153