on 02-26-2018 6:20 AM
Hi experts,
I have developed a custom standalone UI5 application which will run on HCP (CP/CF).
My Requirement is to get current logged user principle without any java code.
is there any possibility to get user principle in UI5 application.
If yes pls guide me on this issue.
Thanx and Regards
Rishabh
Hi Rishabh,
Please use Third party API to get the principal users .
OR
SAP HCP provides a service which can be used to obtain user information as well as log off the user. The details regarding the userapi can be found at
https://help.hana.ondemand.com/help/frameset.htm?1de599bf722446849d2b2e10132df42a.html
Here’s is the example on how this can be acheived within SAP Web IDE.
Add a route into the neo-app.json to reference the userapi
{
"path": "/services/userapi",
"target": {
"type": "service",
"name": "userapi"
}
}
Create a json model to call the service
var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");
sap.ui.getCore().setModel(userModel, "userapi");
Now within a view create some fields to display the data returned by the service
<Label text="User Name"></Label>
<Text xmlns="sap.m" text="{userapi>/name}"></Text>
<Label text="First Name"></Label>
<Text xmlns="sap.m" text="{userapi>/firstName}"></Text>
<Label text="Last Name"></Label>
<Text xmlns="sap.m" text="{userapi>/lastName}"></Text>
<Label text="Display Name"></Label>
<Text xmlns="sap.m" text="{userapi>/displayName}"></Text>
<Label text="Email"></Label>
<Text xmlns="sap.m" text="{userapi>/email}"></Text>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This blog helped for me https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/
The blog uses the mail address as example but you can get more info about the user if needed.
kr, Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to get logged in user info in SAP UI5 deployed in CF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ajay,
I haven't tried the below snippet,
var oUser = sap.ui2.shell.getUser();
oUser.load({}, function() {
var userID = oUser.getId();
}
Try if it works.
Regards,
Ashmita Sinha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Rishabh,
Are you able to use the same "userapi" service for the projects which will run on CP and CF?
I have used this service in a project and deployed the same in CF, but it fails to get data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rishabh,
try this.
var oUser = sap.ui2.shell.getUser();
oUser.load({}, function() {
var userID = oUser.getId();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
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.