cancel
Showing results for 
Search instead for 
Did you mean: 

currentUser values within UI5 lifecycle functions

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

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")

Former Member
0 Kudos

Thanks Maksim!

The first part of the question is OK.

For the second part, i am a bit confused?

what is "my"? Did you mean "this"?

Also, should we not declare "userInfoLoaded" before?

Obviously i ask this as the code in as-is does not work. Also, i tried playing as well but did not manage to get it to work.

former_member182372
Active Contributor
0 Kudos
var userInfoLoaded = $.Deferred();

my.EventChannel = "MyEventChannel";

my.publishEvent = function(eventId, data) { sap.ui.getCore().getEventBus().publish(my.EventChannel, eventId, data); }

my.subscribeToEvent = function(eventId, fnc, _obj) { sap.ui.getCore().getEventBus().subscribe(my.EventChannel, eventId, fnc, _obj); }

my.eventBus = function() { return sap.ui.getCore().getEventBus() };

my.events = {

  USER_INFO_LOADED : "UserInfoLoaded"

};

Former Member
0 Kudos

I managed to get to it work in a "test app" but still have issues in my actual app. It should be something i should be missing.

Anyways, great thanks for your help Maksim!!

Answers (0)