-1

I have an OData service which is made in manifest.json

In some services I need to pass some url parameters like ?$expand=XYZ

SO the question is how can I set serviceUrlParams in the run time and not inside of the manifest.json while the OData model has been created by component class.

  • Does this answer your question? [ODataModel passing "expand" parameter in read](https://stackoverflow.com/questions/43255561/odatamodel-passing-expand-parameter-in-read) – Boghyon Hoffmann Jul 13 '21 at 15:07

3 Answers3

0

There seems to be a misunderstanding that parameters such as $expand belong to the serviceUrlParams. No, we need to distinguish between

  • Metadata URL parameters: metadataUrlParams in model definition. Those parameters will be only attached to the $metadata request which is at the model instantiation.
  • Service URL parameters: serviceUrlParams in model definition. Those parameters will be attached to all requests.
  • Data URL parameters:

For $expand, data request parameter is what you have to define in each binding definition whereever it's needed. Then, the respective data will be loaded on-demand.


API Reference: ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel
Documentation: ui5.sap.com/#/topic/6c47b2b39db9404582994070ec3d57a2

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
-1

Hope this will helps.

var oModel = sap.ui.getCore().getModel();
oModel.read("/entityset?$expand=" + dynamicValue,mParameters);
Sri ram
  • 90
  • 4
  • I tested. The problem is that sapui5 removes $expand form the path. –  Apr 07 '17 at 11:01
  • @Martin @Sriram: In order to be able to use `expand` in the read method, you can use [`urlParameters` in the option map](https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.v2.ODataModel.html#read) and pass `"$expand": "ToXYZ"`. [Here](http://stackoverflow.com/a/43282067/5846045) is my answer using expand in read. – Boghyon Hoffmann Apr 07 '17 at 16:11
-1

for expand url data use the second parameter of the read function.

oDataModel.read("/yourEntitySet", {
    success:jQuery.proxy(this._yourSuccessCallback, this),
    urlParameters: {
        "$expand": "YourExpandData"
    },
    error: jQuery.proxy(this._yourErrorCallback, this)
});
Andreas
  • 636
  • 1
  • 12
  • 29