Search code examples
odatasapui5

OData entity set not retrievable in SAPUI5


I am trying to fetch some data from the backend and I have the following code:

I defined the oData service in the manifest.json:

"DummyName": {
            "type": "sap.ui.model.odata.v2.ODataModel",
            "settings": {
                "defaultBindingMode": "TwoWay",
                "defaultCountMode": "Request",
                "sequentializeRequests": true
            },
            "dataSource": "C_VIEW",
            "preload": true
        }
    }

and I have the following coding in my controller:

var oModel = this.getView().getModel("DummyName");

I retrieve the service and then I can do the following:

I'll get the path to the parent node and I save it in the variable sPath.

 var sPath = this.getPath();

Now that parent node has basically two subnodes I can call with expansion like the following:

var subnode1 = oModel.getProperty("/" + sPath + '/subNode1');

so far this works great, what doesn't work is if I do the same with my subNode2:

var subnode2 = oModel.getProperty("/" + sPath + '/subNode2');

variable subnode2 will remain undefined, I checked oModel in the console and saw some weird behavior:

for that subnode1 I will see a ___list: I can open and find the exact subnode I can retrieve with the sPath + expansion, for the subnode2 I see instead a __defereed: with some super weird URI behind, maybe someone knows what is missing here?


Solution

  • I found a way to do that, I think it might be helpful for others, if this helped you give ma a +1 :)

    I bind the List I will use the metadata directly doing this:

    <List id="myListId" class="sapUiResponsiveMargin" width="auto" 
                items="{
                    path: 'Alias>/I_CdsView',
                    parameters: {expand: 'subNode1,subNode2'},
                    }]
                }"
            >
    

    By the way: it is really important that you have no space between subNode1 and subNode2 there is only a comma that devides both, wasted a couple of minutes there as well because I used a space after the comma.