Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

currentUser values within UI5 lifecycle functions

Hi,

I have two question relating to the currentUser(/services/userapi/currentUser)

  • Except for name and displayName, rest of the fields are blank. Where could be the issue? I need other fields such as email, firstName, lastName, etc.
  • I want to filter the table data with the logged in user but although it shows the value on the UI control, it is empty within the lifecycle funtions(onInit, onBeforeRendering, onAfterRendering ) of the view. How can i get the values within these lifecylce funtions?

Thanks in advance!

Cheers

Jayant

replied

1) data is coming from HCP user service, whatever your identity provider (SAP ID by default, or SAML if configured) returns, you will see there. For me for example it is

{"name":"P057284","firstName":"Maksim","lastName":"Rashchynski","displayName":"Maksim Rashchynski (P057284)","email":"makra.consulting@gmail.com"}

2)

place in Components init

var oModel = new sap.ui.model.json.JSONModel();

oModel.attachEvent("requestCompleted", function() {

  userInfoLoaded.resolve();

  my.publishEvent(my.events.USER_INFO_LOADED);

}, this);

oModel.loadData("/services/userapi/currentUser");

this.setModel(oModel, "userInfo");

so in controllers you can access it like

this.getView().getModel("userInfo").getProperty("name")

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question