cancel
Showing results for 
Search instead for 
Did you mean: 

Save property from OData list into variable

pearlalex
Explorer
0 Kudos

I am trying to get a property from an OData list saved into a variable in javascript.

The model looks like this:

Eg. if I want to store the property Werks from list "0001", I can do it like this:

oModel.getProperty("/ZcountWerksSet('0001')/Werks")

The problem is, this is a dynamic list. I don't know what the values in the parentheses are, but I know the order of the list. Should it not be possible to do something like this then:

oModel.getProperty("/ZcountWerksSet/0/Werks")

This is not working, it returns "undefined".

How can I store the property "Werks" from the first element in the "ZcountWerks" list into a variable in JavaScript?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Alexander,

As you want to get the first item always, you can use getItems()[0] method.

var oItem = oList.getItems()[0];
var path = oItem.getBindingContext().sPath;
var werks = oList.getModel().getProperty(path).Werks;

Answers (0)