Skip to Content

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

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jul 27, 2019 at 02:29 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.