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

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

    1. Jay Prakash Singh 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

      (0) 
      1. Satya 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

        (0) 
        1. 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”);
           
          (0) 
          1. Satya 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

            (0) 
              1. Satya 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

                (0) 
                      1. Satya 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

                        (0) 
  1. Jeanne Loreto

    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.

    (0) 

Leave a Reply