1
votes

I am working on a Master-Detail app. I have a view with list control and I am binding the same with the data from an entityset called "entityset1".

Odata -> data from the entityset1
<serialno>122333</serialno>

I do have another entityset called entityset2 in the same service.

Odata -> data from the entityset2
<hdata>is Active</hdata>

Data from above entityset2 will only be retrieved with the filter (/sap/opu/odata/sap/My_SRV/entityset2?$filter=(serialno=122333)

I am now trying to retrieve the value from the entityset2 and trying to bind it to one attribute in my list. This list is already binded with the entityset1 data.

Myview.xml.

<List id="list" select="_handleSelect">
    <ObjectListItem id="MAIN_LIST_ITEM" press="_handleItemPress" title="{Name}">
        <attributes>
            <ObjectAttribute id="ATTR1" text="{serialno}" />
<ObjectAttribute id="ATTR2" text="{entityset2/hdata}" />            
        </attributes>
    </ObjectListItem>
</List>

Controller.js (binding using the below lines)

this.oList.bindAggregation("items", {
            path: '/entityset1',
            template: this.oListItem,
            filters: this.searchFilters
        });
var oserialnum = this.getView().getBindingContext().getObject().serialno;
var oHdata = new sap.ui.model.Filter("serialno", "EQ",oserialnum);
this.searchFilters = new sap.ui.model.Filter([oserialnum],true);
                this.oList.bindAggregation("items",{    
                    path : "/entityset2",   
                    filters :this.searchFilters
                }); 

However I am getting an error "Cannot read property 'getObject' of undefined" on this line "this.getView().getBindingContext().getObject().serialno".

Can someone kindly advise how to retrive the data from the entity2 and binding it to the list, ?

3

3 Answers

1
votes

You cannot get BindingContext using the view. Read more about binding Context - it's a pointer to an object in Model data.

Also, serialNo(the parameter you are trying to retrieve from the Model is also contextual i.e. it differs with each row item).

One way to do this would be:

onListeItemPress Event of the List

<ObjectListItem ... ... press="onListItemPress" >

In the corresponding Controller

`onListItemPress : function(oEvent){

var oserialnum = Event.getSource().getBindingContext("mainODataModel")..getProperty("serialNo")`

Let me know if this helps.

1
votes

If I understand you correctly what you need is associations.

They will allow the OData Service to deliver the needed Data from entityset2 directly with the entityset1 through "associating" entityset2 with your serial number.

If you are using a SAP Backend and SEGW this Blog might help you:

https://blogs.sap.com/2014/09/24/lets-code-associationnavigation-and-data-provider-expand-in-odata-service/

1
votes

I was faced with a similar issue whilst creating a Master-Detail App, but found out from the SAP Forums that this is not possible, which makes sense and ended up creating a separate entityset in the Backend having a link to the other set