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
Hi JP,
Can please complete your step 5 ? what code exactly need to be added to access the service in UI level.
Thanks, BK
Please explain step 5, to make this blog complete.
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
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
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/");
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
Hi Satya,
Can you please provide screen shot of the destination created in WEBIDE?
Hi Srinivasan,
I am using Local WEBIDE and below is the screen snap for destination.
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
Is the destination displaying properly in neo-app.json file
It's displaying correctly in neo-app.json file.
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.
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.
I have created new thread in scn, can you check it once and please help me http://scn.sap.com/thread/3925049
Thanks,
Satya
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.
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
Thanks mate.
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.