cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get data from oData binding

jakob_steen-petersen
Contributor
0 Kudos
876

Hi

I need to read data from my default model (oData). I try this code

var oDataModel = this.getModel()
var test = oDataModel.getProperty("/PurchaseOrderSet");

But test is "undefined" - what do i do wrong?

Here is debug where you can se data is in there:

Accepted Solutions (0)

Answers (3)

Answers (3)

sergey_muratov
Participant
jakob_steen-petersen
Contributor
0 Kudos

I don´t need to Read anything. Data is read and bound ok.... Check debugger screenshot

sergey_muratov
Participant
0 Kudos

Then you are passing bad data path to getProperty. It shoud be like

oModel.getProperty("/Customer('ALFKI')/Address");<br>

In your code you only passed EntitySet identifier. No id of an entity, no property of an entity.

jakob_steen-petersen
Contributor
0 Kudos

Hi Sergey

You are right - almost 🙂

The problem was that i need to include the key to the string:

oDataModel.getProperty("/PurchaseOrderSet('4500000999')/Field1");

Problem is then: what if the field i need actually is the key?

sergey_muratov
Participant
0 Kudos

Hi

I don't see any problem. Key is a special property. It also has identifier. For example "/PurchaseOrderSet('4500000999')/KeyFieldId".

TuanNGO
Newcomer
0 Kudos

you can use this snippet to get the bound data for the whole table.
if you're using sap.m.Table, change the aggregation binding "rows" with "items". it should work also.

oTable.getBinding("rows").getAllCurrentContexts().map(row => { return row.getObject() } )

 

 

former_member709916
Participant
0 Kudos
onInit: function () {
            var sUrl = "/northwind";
            var oModel = new sap.ui.model.odata.v2.ODataModel(sUrl);
            oModel.read("/PurchaseOrderSet", {
                success: function (data, response) {
                    console.log(data);
                },
                error: function (error) {
                    var errorCode = error.statusCode;
                    var status = error.statusText;
                    MessageBox.error(errorCode + ":" + status);
                }
            });
            this.getView().setModel(oModel);
        },

jakob_steen-petersen
Contributor
0 Kudos

Hi Nadya

Thanks - but i must have been un-precise: case is that i already have read data from the backend. No problem there.

But i have a function where i need to use some data from the data fetched. Basically i need the value of some fields in the PurchaseOrderSet (like Purchase Order Number and other things) to use them for other things.