cancel
Showing results for 
Search instead for 
Did you mean: 

Odata model sends request many times

Former Member
0 Kudos

Hi,

I have a odata model. Whenever the function is called, the request gets sent twice. Here is my code

     populateTable:function(SalesOrg, FiscalYear, FiscalPeriod, CustomerHierarchy1, ProductLine, searchFilter){

        var oRowTemplate = new sap.m.ColumnListItem({

        cells : [

            new sap.m.Text({text : "{CustomerHierarchy1}" }),

            new sap.m.Text({text : "{ProductFamily}"})

            ]}

        ); 

        var oTable =this.getView().byId("populateTable");

        oTable.bindItems({

                path: URL.populateTable.entity,

                template:oRowTemplate

        });

        var oModel = new sap.ui.model.odata.ODataModel(URL.populateTable.service, true);

        alert(oModel);

        oTable.setModel(oModel);

  }

The alert is popped up only once. However, the request is twice. Everything including the URL parameters and response are same.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Please find the code here. JS Bin - Collaborative JavaScript Debugging

former_member182372
Active Contributor
0 Kudos

oModel.setDefaultCountMode(sap.ui.model.odata.CountMode.None);

Former Member
0 Kudos

I am still facing the issue.

former_member182372
Active Contributor
0 Kudos

so, populateTable is executed twice. set a breakpoint there and see a stack trace (or post screenshots of both here 😉 )


btw, creating an odata model is pretty heavy opertion as it includes donwloading and parsing metadata so i would not do it in a "business" methods rather in init/onInit of components/controllers

Former Member
0 Kudos

The function is getting executed only once. I tested with both alert and console.log My use case is,

I have to load the first 10 rows out of 1 million rows. When the user clicks on more button, I hit the server and retrieve the next 10 rows. For this use case, I thought we can only use odata model.

SergioG_TX
Active Contributor
0 Kudos

Senthil.. you have the right idea.. the table control itself will make the calls to retrieve ( X number of rows ) when you switch pages via the pagination of the table. please create a jsbin example.. it will probably be easier to follow and guide you.

former_member182372
Active Contributor
0 Kudos

just

oTable.setGrowingThreshold(10) and sap.m.Table will take care of the rest (OData query options $top and $skip)

SAPUI5 SDK - Demo Kit

SergioG_TX
Active Contributor
0 Kudos

is the entire request completed??? look into the chrome developer tools and you will see if the request is truly being completed x many times. at most one request is completed but maybe many will fire.

check the developer tools and let us know your findings

Former Member
0 Kudos

Both the requests are completed. The second request is triggered as soon as the 1st one is completed.

SergioG_TX
Active Contributor
0 Kudos

are there other events triggering the second request?

move the oTable.bindItems function after setting the model.

remove the alert - use a console.log( )  instead

Former Member
0 Kudos

Yes, i tried those. Still, 2 requests are sent.

SergioG_TX
Active Contributor
0 Kudos

it's hard to tell without much more code