cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Save single property from OData model into a variable

pearlalex
Explorer
0 Kudos

I'm trying to save a property from an OData model into a variable like this:

var myModel = this.getView().getModel();
var value = myModel.getProperty("/ZcountGeneralSet('')/Werks");
// value returns undefined

I'm wondering if the syntax for empty parameter (' ') is wrong, because it works if I pass in the number that "Werks" shall return (7001). The property can also be retrieved when calling ZcountGeneralSet(' ')/Werks in the odata service in a browser, but not in sapui5.

Is there another way or another syntax to retrieve the property in sapui5?

(Maybe another syntax for passing empty parameter?)

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

check in dev tool to see what is inside of your model. if you see ZcountGeneralSet(' ') as an obj in your model, you should be able to get it.

pearlalex
Explorer
0 Kudos

I can only see ZcountGeneralSet('7001') as an object inside dev tool, not with empty parameters. But browser returns the right value even without the 7001-parameter. Strange, or? (We don't know what the parameters shall be before we call the function without the parameter..)

junwu
Active Contributor
0 Kudos

what's your model version?

the call you made in browser, it goes to gateway to retrieve data.

the other case, you are just asking from the model.....

pearlalex
Explorer
0 Kudos

It's set as version 2.0 in manifest.json

junwu
Active Contributor
0 Kudos

use "read" to call that url first, then I think you get that value from model