cancel
Showing results for 
Search instead for 
Did you mean: 

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

zaberca_david
Explorer

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

Accepted Solutions (1)

Accepted Solutions (1)

maheshpalavalli
Active Contributor

Or you can simply access it like below, assuming that ur app is inside the launchpad

sap.ushell.Container.getService("UserInfo").getUser()

https://sapui5.hana.ondemand.com/sdk/#/api/sap.ushell.services.UserInfo

BTW, you probably shoud remove /oModel from the path:

userModel.getProperty("/name");

BR,

Mahesh

zaberca_david
Explorer
0 Kudos

The problem was I was using path /oData/name and not /name. Every other discussing mentions using /oData and nobody fixed it, until now. Many thanks to you, Mahesh.

Answers (0)