cancel
Showing results for 
Search instead for 
Did you mean: 

userapi does not contain data when logged on

0 Kudos

Hi all,

we built an SAPUI5 app on HCP and run it in a FLP. Now we are trying to get rid of its login screen by using the HCP userapi. I implemented a route to it in neo-app.js .

  •         "path": "/services/userapi"
  •         "target": { 
  •             "type": "service"
  •             "name": "userapi" 
  •         } 
  •     } 


I initialize the model in my Login.controller.js like this:


onInit: function() {
var oModelUserCurrent = new sap.ui.model.json.JSONModel("/services/userapi/currentUser"); 
var strUserName = oModelUserCurrent.getProperty("/name");


Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Sorry for continuing here, but the web editor had a problem in handling the code snippet I took from webide directly.

In the case above

oModelUserCurrent,getData()  returns undefined

I checked oModelUserCurrent.oData in chrome debugger - it is empty.

strUserName is undefined as well.


Any helpfull proposals and ideas for solving this are very much appreciated.


Thanks and best regardes


Wolfgang

Former Member
0 Kudos

Hi Wolfgang,

This is the portal service space and your question should be in the UI5 space, however from an initial look in your question, you are creating a model and then immediately trying to get its data, before the model finished fetching the data from the server.

You should use oModelUserCurrent.attachRequestCompleted to read the data in your model.

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.Model

Regards,

Guy

0 Kudos

Hi Guy,

thanks a lot. Solves the issue. Solution makes sense. Its interesting, I took this code from a thread in here (SCN) which is referenced quite often. Seems the example given there is wrong.

best regards

Wolfgang

Answers (0)