Scenario where I have to create an application that might have more destinations in future

65 views Asked by At

I was just wondering: is it possible to add more destinations/services dynamically in my UI5 application rather than using it in manifest?

For example: let us assume currently I know of a service A that I'm going to use.
So I will add that service, create model in manifest and consume through OData. But what if in future the requirement changes, and now they want to be able to select system as well, so that the service A from that particular system is selected and data is fetched from that destination only? (Assuming service is same in all systems).

1

There are 1 answers

0
A.vH On

Services defined in the manifest.json help you during initialization of your app.

It shouldn't be a great problem to define a new model at runtime in the controller, e.g.

var oModel = new sap.ui.model.odata.v2.ODataModel("http://services.odata.org/Northwind/Northwind.svc/");

And set it as new View Model

this.getView().setModel(oModel);

or change the bindingContext of a Control to it

oControl.setBindingContext(oContext,"myModelName");

If you encounter CORS-Problems and have to define destinations in the SAP Cloud Platform Cockpit upfront, then this might be a bit more difficult. But in your case (service is same in all systems) that won't be a problem.