Skip to Content
0
Jul 26, 2019 at 09:08 PM

Get property of sap.ui.model.Model always returns undefined

805 Views Last edit May 21, 2020 at 03:19 PM 2 rev

Hello experts,

I think this question has been discussed a million times and the solution is never working.

I'm getting the /services/userapi Model loaded into component.js and then retrieve it in another view. The object is there, as I checked in debugger. Inside the model, I want to get the user id, more precisely from /oModel/name.

I'm accessing the value like this:

var userModel = sap.ui.getCore().getModel("UserInfo");

var userId = userModel.getProperty("/oModel/name");

I checked in debugger, took it step by step. The name is there. The path is correct. It always returns undefined. What is going on? I also tried attaching it to a request complete event. It doesn't work. Also, oData is private and can't access the value directly.

Can you help me out please?

Thanks in advance,

David