-2

I am trying consume an OData service(http://services.odata.org/Northwind/Northwind.svc) in SAPUI5 but it does not return any data

My controller code is as below enter image description here

Dialog.fragment.xml

<core:FragmentDefinition
    xmlns="sap.m"
    xmlns:core="sap.ui.core">
    <SelectDialog
        title="Products"
        class="sapUiPopupWithPadding"
        items="{/CategoryName}"
        search="_handleValueHelpSearch"
        confirm="_handleValueHelpClose"
        cancel="_handleValueHelpClose">
        <StandardListItem
            
            title="{CategoryName}"
             />
    </SelectDialog>
</core:FragmentDefinition>
Community
  • 1
  • 1
Rubens P. P.
  • 19
  • 1
  • 9
  • What shows on your chrome console? Any errors? – Haojie Mar 08 '17 at 15:45
  • 1
    ----https://sapui5.hana.ondemand.com/sdk/resources/sap/ui/thirdparty/datajs.js?eval Failed to load resource: the server responded with a status of 404 (Not Found) ----- ---Failed to load resource: the server responded with a status of 404 (Not Found)---- ---Uncaught (in promise) Object sapui5.hana.ondemand.com/sdk/resources/sap/ui/core/library-preload.js:1956 Uncaught (in promise) Object---- ----Failed to load resource: the server responded with a status of 404 (Not Found)---- – Rubens P. P. Mar 08 '17 at 16:02

2 Answers2

1

You seem to have an incorrect URI in your model declaration. The image shows the model path assigned as

var sServiceUrl = "8080/http/services.odata.org/V2/Odata/Odata.svc";

This is the reason for the 404 error, you will have to change this to

var sServiceUrl = "http://services.odata.org/Northwind/Northwind.svc";

Also, you have an invalid binding for your SelectDialog. The Odata metadata does no have a EntitySet named "CategoryName". You will have to change this to "Categories".

<SelectDialog
    title="Products"
    class="sapUiPopupWithPadding"
    items="{/Categories}"
    search="_handleValueHelpSearch"
    confirm="_handleValueHelpClose"
    cancel="_handleValueHelpClose">
    <StandardListItem

        title="{CategoryName}"
         />
</SelectDialog>

Edit: As it seems that you are using SAP WebIDE, it would be a good idea to add services.odata.org as a Destination in HCP

Stephen S
  • 3,936
  • 2
  • 23
  • 33
  • Now I get same errors in my console. The errors are: Uncaught (in promise) Object {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…ces.odata.org/Northwind/Northwind.svc/$metadata'.", request: undefined, response: undefined} Uncaught (in promise) Object {xmlDoc: document} sapui5.hana.ondemand.com/sdk/resources/sap/ui/thirdparty/datajs.js?eval:17 XMLHttpRequest cannot load http://services.odata.org/Northwind/Northwind.svc/$metadata. Response for preflight has invalid HTTP status code 501 Failed to load resource: the server responded with a status of 404 (Not Found) – Rubens P. P. Mar 09 '17 at 11:22
  • That's a Cross-origin error that you get, as you are referencing the service from a domain which does not allow cross-origin requests. You should add the Service as a Destination in HCP or run your browser in Cross-origin mode. – Stephen S Mar 09 '17 at 11:25
  • I ran in the Internet Explorer and I don't get any error in console, but the Dialog don't show any data – Rubens P. P. Mar 09 '17 at 11:39
  • you can enable cross-origin in IE: Internet Explorer > Tools > Internet Options. Select the Security Tab & click on Custom Level button. In the Settings under Miscellaneous > Access data sources across domains, select Enable – Stephen S Mar 09 '17 at 11:44
  • 1
    I would suggest you to add a HCP Destination for the service as that is the standard way of implementing a service. You can refer to the [documentation](https://sapui5.hana.ondemand.com/#docs/guide/3a16c7a2f1e944deb000db49e5ece6be.html) and [this](https://blogs.sap.com/2014/07/07/how-to-use-northwind-odata-service-with-sap-river-rde/) SCN Post – Stephen S Mar 09 '17 at 12:28
0

You binded the items aggregation of the SelectDialog to the "/CategoryName" collection, but this collection does not exist in the OData service. I guess you meant to bind it to the Categories collection instead.

Serban Petrescu
  • 5,127
  • 2
  • 17
  • 34
  • Now I get same errors in my console. The errors are: Uncaught (in promise) Object {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…ces.odata.org/Northwind/Northwind.svc/$metadata'.", request: undefined, response: undefined} Uncaught (in promise) Object {xmlDoc: document} sapui5.hana.ondemand.com/sdk/resources/sap/ui/thirdparty/datajs.js?eval:17 XMLHttpRequest cannot load http://services.odata.org/Northwind/Northwind.svc/$metadata. Response for preflight has invalid HTTP status code 501 Failed to load resource: the server responded with a status of 404 (Not Found) – Rubens P. P. Mar 09 '17 at 11:24