cancel
Showing results for 
Search instead for 
Did you mean: 

Get loved userId in SAPUI5 Application

juanforero5
Participant
0 Kudos
1,303

Hi everyone!

I am trying to get the user id that is logged in using a button in an SAPUI5 application and I'm doing it this way:

I don't know if the way I call the ID is correct, but it doesn't return anything. Does anyone know why this is?

Greetings from Colombia!

View Entire Topic
jorta
Participant
0 Kudos

Hello Juan,

you can use the User api. For it add this to your neoapp.json file:

And then add this to your controller:

var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");
userModel.attachRequestCompleted(function () {
         var userId = userModel.getData().name;
         ........
});

or with ajax

jQuery.ajax({
        type: "GET",
        contentType: "application/json",
	url: "/services/userapi/currentUser",
	dataType: "json",
	async: false,
	success: function (data) {
	        _userId = data.name;
		_displayName = data.displayName;
		......
	}
});
juanforero5
Participant
0 Kudos

Hi Juan Carlos.

Thank you very much for your answer. I have implemented the function as you suggest, but when I run the application in Fiori Launchpad I get: