cancel
Showing results for 
Search instead for 
Did you mean: 

How to read data from getOwnerCompoent model

0 Kudos

Hi ,

I have created a sapui5 application and added a oData service to it by givine the model name as 'mainService' . I have multiple entities that are exposed in the oData service.

how to get the data from using the model inside the application.

I am trying out with the below code:

this.getOwnerComponent('mainService').getData()

this returns null

I want to get the data of each entity and do some action based on the data. I don't want to go for model.read and wait for the success call back as there is much delay to reach success call. Can any one help how to get this done.

Accepted Solutions (1)

Accepted Solutions (1)

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert

Hi cfsapdemo17,

The model data will only have data when you perform a read request.

If you really need to have data on it before the life-cycle reaches the UI painting in the user interface, you ought to do it in the init method with a read request.

Note that read request shouldn't take too long. If it would take too long, then it would make your application initialization block the browser and have users waiting on the initial call. You must figure out what could reduce the round-trip of your OData service to be below 1s.

In most cases, you are probably trying to bring non-essential data to the UI. Keep in mind that OData calls should always have a very small data subset that corresponds to the data a user is able to see in the UI. Suppose you have a table with 10 rows - you don't want to page the ten rows in the browser. You are much better off by using the paging mechanism of OData, so it fetches just exactly 10 rows in a single round-trip.

In essence, you will want to?:

1) Avoid using XML based services at all costs - always use JSON as response type ($format=json).

2) Avoid using $expand on OData fetch at the application initialization phase. If you must use $expand, use it only when you are displaying a detailed data (for instance: header and items)

3) Use $top and $skip as much as possible

4) If you need to display number of pages and amount being displayed use $count and/or $inlinecount

4) Fetching only the columns that are really used in the UI (visible) using $select

5) If you store configuration data for the UI on an OData service for visual component's visibility or to adapt the UI according to a certain user's profile, than do it using a single row fetch. I would suggest combining the true/false values in a single column - so you could set the visibility of UI components based on the index of that particular value (ex: ui_role[1] means a particular field is visible). This way you would minimize the size of the JSON response you are retrieving.

6) user $filter as much as possible

If you have any doubts on the OData usage that I briefly talked above, please visit the following documentation page:

https://www.odata.org/documentation/odata-version-2-0/uri-conventions/

Hope this helps.

Best regards,
Ivan

Answers (0)