cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing xsodata service from UI5 application in SAP Web IDE full stack

Hi there,

I am following this guide that explains how to create XSODATA services in SAP WEB IDE full stack and access them via the HTML5 component in the same Project.

The guide is talking about creating a sample UI5 application, accessing the model euro.xsodata (page 41), adding this as a destination in the xs-app.json file in the UI application, and then adding the destination in the mta.yaml file to point to the nodejs application where the euro.xsodata service is located.

I have followed the steps, however, the ui5 app is unable to connect to the nodejs xsodata service. I have a feeling that it is unable to read my parameters in this xs-app.json file, as even if I corrupt this json with some random characters the application runs fine without the data.

The following error is shown in the browser console:

xs-app.json:

{"welcomeFile":
"/ui5hana/index.html","authenticationMethod":
"none","logout":
{"logoutEndpoint":
"/do/logout"},"routes":
[{"source":
"^/ui5hana/(.*)$","target":
"$1","localDir":
"webapp"}, {"source":
"^/euro.xsodata/(.*)$","destination":
"tinyjs_be"}]}

mta.yaml:

  - name: tinyjstype: nodejs  path: tinyjs  provides:  - name: tinyjs_api  properties:  url: '${default-url}'  requires:  - name: hanamod  - name: hdi_hanamod  - name: ui5hanatype: html5  path: ui5hanaparameters:  disk-quota: 256Mmemory: 256M  build-parameters:  builder: grunt  requires:  - name: tinyjs_api  properties:name: tinyjs_be  url: 
~{url}group: destinationsProject screenshot:

Project screenshot:

Any pointers would be appreciated. Thank you!

Accepted Solutions (0)

Answers (3)

Answers (3)

I ultimately got it to work by adding the xsodata service as part of a new http odata destination in the neo cloud, and then added a data source in the manifest.json accessing this odata service and a new model accessing this data source.

It works - but I feel it is a round-about way to access a service within the same MTA project.

If you have any other suggestions, let me know.

Thanks,

esjewett
Active Contributor
0 Kudos

Yeah, this is really not the right way to do things 🙂 You just have a URL mapping issue, I think, and need to spend a little time adjusting your services module and your xs-app.json file to see how the routing works.

esjewett
Active Contributor

How are you accessing the service in UI5? Based on your xs-app.json, it looks like the path should be

/euro.xsodata/euro.xsodata/$metadata

which is not what your UI5 code is hitting. You'll probably want to correct both the source in your xs-app.json and whatever UI5 code is accessing the service, or the manifest.json if that is where it is defined.

0 Kudos

Hi Ethan,

Thanks for the reply.

I am accessing the service via the index.html sample code given in the example, i.e:

<script>var oModel = new sap.ui.model.odata.ODataModel("euro.xsodata", true);var oTable = new sap.ui.table.Table({ title: "European Countries" });oTable.addColumn(new sap.ui.table.Column({ label: "Country Name",template: "name" }));oTable.setModel(oModel); oTable.bindRows("/euro");oTable.placeAt("content");</script>

Why do you think that it is taking the path as /euro.xsodata/euro.xsodata/$metadata?

The error message shows the /euro.xsodata only once.

I tried to get it to work via the manifest.json, but I am not sure how to add the model correctly on the manifest.json. In the past when I was using the neo platform on sap cloud, I could add a destination in neo and access the odata service via the http destination type however in this case as both the UI5 and the node.js modules are inside the same project, I am not sure how to cross reference it. Would you know how my manifest.json file should be configured to get this to work?

Thanks,

LM

esjewett
Active Contributor
0 Kudos

I was just saying that it looks like the URL you are accessing in the model is different from the URL defined in your xs-app.json. Given the xs-app.json you shared, I think your model should look like:

var oModel =newsap.ui.model.odata.ODataModel("euro.xsodata/euro.xsodata", true)

You should also really switch to the v2 model (https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel) as the API you are using is deprecated.