Skip to Content
0

How to get the user principle of logged user in UI5?

Feb 26 at 06:20 AM

62

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Feb 26 at 06:28 AM
0

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.

Adding the User Details to a View

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>

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 26 at 06:38 AM
0

Hi Rishabh,

try this.

var oUser = sap.ui2.shell.getUser();

oUser.load({}, function() {

var userID = oUser.getId();

}

Share
10 |10000 characters needed characters left characters exceeded
Ashmita Sinha
Jun 24 at 05:56 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded