Skip to Content
Author's profile photo Former Member

How to add ODATA Service on SAP UI5 application available in Web IDE

Hi Everyone,

I want to discuss the way in which we can use ODATA service into SAPUI5 application available into the Web IDE.

Right now when we are creating SAPUI5 application from Web IDE it is not asking to attach ODATA service and hence we are not able to access the service, I am writing this blog as I saw some blog where this question was raised.

Solution : To add ODATA service you have to follow below steps.

1. Create your sap ui5 application like you are creating.

2. Now select the application and go to File -> New -> Odata Service

3. Now from here it will be same as we are doing for FIORI.

4. After you finish with adding of odata service in your application , check manifest.json file and you will be able to see your service now added.

5. Now you have to do same as you are doing in FIORI to access the service.

Thanks,

JP

Assigned Tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi JP,

      Can please complete your step 5 ? what code exactly need to be added to access the service in UI level.

      Thanks, BK

      Author's profile photo Former Member
      Former Member

      Please explain step 5, to make this blog complete.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Vinod,

      Blog is complete.

      You want a code through you can access your service so code is here.

      var sServiceUrl = this.getMetadata().getManifestEntry("sap.app").dataSources["ZATTACHMENTMORE_SRV"].uri;

        var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl);

      sap.ui.getCore().setModel(oModel);

      Also try with destination key word in your url.

      Thanks,

      JP

      Author's profile photo S G
      S G

      Hi JP,

      Thanks for information.

      I got an error while executing your code in onInit() method i.e.,

      var sServiceUrl = this.getMetadata().getManifestEntry("sap.app").dataSources["XXXXXXX"].uri;

      var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl);

      sap.ui.getCore().setModel(oModel);

      Error : UIComponent.js:6 Uncaught TypeError: this.getMetadata(...).getManifestEntry is not a function

      I am not able to consume data through OData service, How can I get URI from manifest file and how can I pass that URI to ODataModel?

      And  as you said second point "Also try with destination key word in your url", I don't know how to do this.

      Please help me on this.

      Thanks & regards,

      Satya

      Author's profile photo Srinivasan S
      Srinivasan S

      Hi Satya,

      After setting your destination please try the below code in the controller file

      var oModel = new sap.ui.model.odata.ODataModel("/Your ServiceURL/");

      this.getView().setModel(oModel");
       
      Author's profile photo S G
      S G

      Hi Srinivasan,

      My confusion is how can I get that Service URL form WEBIDE destination to pass it to ODataModel,

      I also tried like

      var oModel = new sap.ui.model.odata.ODataModel("/http://xxxxxxxx:xxxx/sap/opu/odata/sap/ZSALES_APP_SRV/SaleOrgSet");

      But I am facing the error that is CROSS ORIGIN error in browser.

      So I thought that,  If I try with WEBIDE destination, this error will not come. Please correct me if I am wrong. 

      And let me know how  can I get the ServiceURL from destination which is configured in manifest.json file.

      Thanks,

      Satya

      Author's profile photo Srinivasan S
      Srinivasan S

      Hi Satya,

      Can you please provide screen shot of the destination created in WEBIDE?

      Author's profile photo S G
      S G

      Hi Srinivasan,

      I am using Local WEBIDE and below is the screen snap for destination.

      2016-06-24 19_08_02-C__WEBIDE.png

      I think don't have any problem with destination file because I can able to import the standard Fiori apps, able extends/customize and able to run those apps.

      Thanks,

      Satya

      Author's profile photo Srinivasan S
      Srinivasan S

      Is the destination displaying properly in neo-app.json file

      Author's profile photo S G
      S G

      It's displaying correctly in neo-app.json file.

      Author's profile photo Srinivasan S
      Srinivasan S

      Have you tried to print the oModel in the console. Further I suggest you look into SAPUI5 Explore.

      You should be able to solve it from there.

      Author's profile photo S G
      S G

      Hi Srinivasan,

      I have downloaded above UI5 Explored application and imported into WEBIDE work space, trying to run that app, I am facing error. below is the screen snap of the error.

      2016-06-30 10_05_37-XML Templating_ UI5 OData types.png

      I have created new thread in scn, can you check it once and please help me http://scn.sap.com/thread/3925049

      Thanks,

      Satya

      Author's profile photo Former Member
      Former Member

      Hi All,

      Just starting off here.  Appreciate some help, I created my sample demo app, created mock data, and wanting to link it to the oData service.  Am getting the error below, "unhandled Error:  Cannot read property" _sap.creatable' of undefined.

      Appreciate any help.

      Thanks.

      Author's profile photo Wanderson Silva
      Wanderson Silva

      It's a bug from Webide. We need to change the file before the upload. See this in https://answers.sap.com/questions/82235/sap-web-ide-odata-connection-mock-data.html

      Author's profile photo Former Member
      Former Member

      Thanks mate.

      Author's profile photo Aparna Vadakanti
      Aparna Vadakanti

      Hi All,

       

      How to consume a oData service in extension App . I tried the way mentioned above it is asking for Model name given but the next button is not getting enabled.

       

      Thanks,

      Aparna.