0
votes

I am trying to consume Gateway OData Services in sapui5 app.

Metadata - /sap/opu/odata/SAP/ZUSER_MANAGE_SRV/$metadata as follows: enter image description here

UserdataSet - /sap/opu/odata/SAP/ZUSER_MANAGE_SRV/UserdataSet as follows: enter image description here

MY CODE

var oModel = new sap.ui.model.odata.ODataModel("http://Host:Port/sap/opu/odata/SAP/ZUSER_MANAGE_SRV", false,"USER","Password");
        
    var app = new sap.m.App("myApp",{});
        
    var oTable = new sap.m.Table("list1", {
                                growing: true,
                                growingThreshold: 200,
                                //mode: sap.m.ListMode.SingleSelect,
                                columns: [
                                    new sap.m.Column({
                                        header: new sap.m.Label({text: "ID"})
                                    }),
                                    new sap.m.Column({
                                        header: new sap.m.Label({text: "First Name"})
                                    }),
                                    new sap.m.Column({
                                        header: new sap.m.Label({text: "Last Name"})
                                    })
                                ],
                                items: {
                                    path: "/UserdataSet",
                                    template: new sap.m.ColumnListItem({
                                        cells: [
                                            new sap.m.Input({value: "{EUname}"}),
                                            new sap.m.Input({value: "{EFirstname}"}),
                                            new sap.m.Input({value: "{ELastname}"})
                                        ]
                                    })
                                }
                            });    
    oTable.setModel(oModel);
    var page1 = new sap.m.Page("page1",{
        title: "App",
        content: [oTable]
    });
    
    app.addPage(page1);
    
    return app;

Getting error as - uncaught exception: [object Object].

Detailed Error: enter image description here

Please help, whats wrong with my code?

2
The error appears to be from metadata call. Can you check in network tab if the metadata call loaded correctly.Veeraraghavan N
Hi @Veeraraghavan, I didn't see any metadata call under network tab. Can you please tell me is there anything else I can dokuljit k

2 Answers

0
votes

Your OData service needs to be on the same server or needs to appear to be coming from the same server as your UI5 application. If it's not on the same server you should get Gateway to produce CORS headers.

Please find more info on CORS and how to get Gateway to produce these headers here: http://scn.sap.com/community/gateway/blog/2014/09/23/solve-cors-with-gateway-and-chrome

0
votes

The Error is not very clear maybe chrome will show an more detailed error in this case.

If your application server and odata service are not from the same origin, the SOP (same origin policy) restricts this action.

Two pages have the same origin if the protocol, port and host are the same for both pages.

see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy for more details.

you can start chrome with --disable-web-security flag: In CMD:

C:/<path to chrome app>/chrome.exe --disable-web-security

!!! ONLY FOR DEVELOPMENT REASONS !!!