Skip to Content

How to get the first value from odata response when using filter parameters in SAPUI5?

Feb 16, 2017 at 05:44 AM


avatar image

Hi all,

I use XML views for coding. I need to get the first value from the odata response when using filter type of odata binding . Here's the controller code what I have tried:

Controller code:


var incrtab = this.byId("idMyApprovalsList");

var oItems =new sap.m.ObjectListItem({

title :"{EmployeeName}" , number:"{AgeingDays}",

numberUnit:"{path: 'CreatedDate',type: 'sap.ui.model.type.Date',formatOptions: {style: 'medium'}}", type : "Navigation",

press: this.handleSOSelect,

attributes:[new sap.m.ObjectAttribute({text :"{EmployeeId}"}),

new sap.m.ObjectAttribute({text :"{ProcessName}"}),

new sap.m.ObjectAttribute({text :"{WorkitemId}", visible:false}) ] });

var filters = new sap.ui.model.Filter("ImUser", sap.ui.model.FilterOperator.EQ, name); incrtab.bindItems("/APPR_PENDING_LISTSet",oItems, null, filters); },

If we use like :,{ success: function(oData,oResponse)});

Then we can get value as: pcode=oData.PaCode;

But in my case, how can I get the "0"th array data or the first values from the list without pressing the list?

Can Someone help me with this?



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member Feb 16, 2017 at 11:38 AM

Hello Ramya Ramasamy,

You have two options to get first element in your odata response:

1) oData.results[0] // here you will get first record in your entity

then get each field

var data = oData.results[0]; / you need to debug when you get success response in call.



or (data) you can directly bind to any control that you want.

2) alternative for list:

var list = sap.ui.getCore().byId("listID_name"); // change list id name

var firstRecord = list.getItems()[0].getBindingContext().getProperty();

Hope his will help you!!!


Mahesh Phajage

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Mahesh,

option 1 cannot be used in my case because, I'm directly binding items to the objectListItem.

I tried the 2nd option in oninit() as you said:

var list = this.getView().byId("idMyApprovalsList"); // change list id name

var firstRecord = list.getItems()[0].getBindingContext().getProperty("EmployeeId");


Now I get an error like:

Uncaught TypeError: Cannot read property 'getBindingContext' of undefined

Kindly help me with this.

avatar image
Former Member Feb 16, 2017 at 09:43 AM

As per oData v2:

"The data requested from an OData service is cached in the OData model. It can be accessed by the getData() and the getProperty() method, which returns the entity object or value. These methods do not request data from the backend, so you can only access already requested and cached entities:"


Try to adjust it to your example

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Radek,

Thanks for your reply.

In my case I don't have that oModel. I'm directly binding it to the objectListItem.

Is there any other way to get the value?

Former Member
Ramya Ramasamy

Yes you do.

var oModel = this.getOwnerComponent().getModel();

This will return you the instance of your global model.