cancel
Showing results for 
Search instead for 
Did you mean: 

xml view binding data from two entitysets

0 Kudos

Dear Experts,

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>isActive</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.

<Listid="list"select="_handleSelect"><ObjectListItemid="MAIN_LIST_ITEM"press="_handleItemPress"title="{Name}"><attributes><ObjectAttributeid="ATTR1"text="{serialno}"/><ObjectAttributeid="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, ?

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member340030
Contributor

I hope its an oData service .. than you can use $expand to get both the values in one request and can bind it to the aggregation of the control.

Few things for knowledge -

1. you can not bind 2 different entities to the same aggregation "items" as you are doing currently.

2. And also don't bind the aggregation like you are doing right now - just bind the model and the element to the view in controller and add items attribute to the list with the entity path.

Thanks

Viplove ..

irfan_gokak
Contributor

Hi Rio,

It's better to merge both the entity sets into one or create deep structure using both. For the list you can bind only one entity to form the items.

0 Kudos

Thank you all, basically the app is a standard Fiori App and I am just starting to extend the same. Please allow me to clarify this.

In My controller the following piece of code is binding the odata ->entityset1 to the Listitem on the Masterview.

ListBinding: function () {
 if (!this.oSearchText) { this.oSearchText = sap.ui.core.routing.HashChanger.getInstance().getHash().split("/")[1];
} 
 this.oList.bindAggregation("items", {
   path: '/entityset1',
   template: this.oListItem,
   filters: this.searchFilters
  });


However before binding it self I need to get the value (serialno) from the entityset1 so that with that value will query the entityset2 and get a value from the entityset2 and bind it to a different control or may be another list. My first mission is to get the value (serialno) before it gets binded to the list.

I have checked the standard app and there is no model defined, hence it is an unnamed model.

I have been tried using this.getView().getModel() and getting undefined error. could one of you suggest how to get the value from entityset1 please.

brian_keenan
Contributor
0 Kudos

In your code, you are only binding the lists, I guess the view is still not bound so getBindingContext() returns undefined

Anyway as others have stated you cannot bind an aggregation to 2 different entities, best bet is to change the model and combine them