on 09-30-2015 9:01 AM
Hi,
I have two question relating to the currentUser(/services/userapi/currentUser)
Thanks in advance!
Cheers
Jayant
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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"
};
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.