2

I've a SAP Fiori application and I need to get the current logged in user details. I've searched web but unable to find a solution.

is there any way to get current logged in user details from launchpad.

0

4 Answers 4

5

There is a UserInfo service from the FLP shell which can be retrieved like this:

{ // In Controller
  doSomethingUserDetails: async function() {
    const userInfo = await this.getUserInfoService();
    const userId = userInfo.getId(); // And since 1.86: .getEmail(), .getFirstName(), .getLastName(), .getFullName(), ... 
    // ...
  },
  
  getUserInfoService: function() {
    return new Promise(resolve => sap.ui.require([
      "sap/ushell/library" // In the future, "sap/ushell/Container" might need to be required instead. Refer to API reference.
    ], sapUshellLib => {
      const Container = sapUshellLib.Container;
      const service = Container.getServiceAsync("UserInfo"); // .getService is deprecated!
      resolve(service);
    }));
  },
}

To align with the current best practices, avoid calling sap.ushell.Container.getService directly! Use getServiceAsync instead.

Alternatively: information about the the current user can be also retrieved via the user API service exposed by the application router from the SAP Business Technology Platform (SAP BTP).


* In case the app is deployed to the old Neo environment, see the previous edit.

8
  • Does this code snippet work for CloudFoundry deployment as well? Jun 28, 2022 at 9:21
  • @ramanareddy438 Should work in CF environment as well. Try it let us know :) Jun 28, 2022 at 12:48
  • @Hoffmann - This is not working in CF. I found a different approach for CF. Jul 19, 2022 at 12:14
  • @ramanareddy438 Have you also tried the User API service mentioned in the answer? Jul 19, 2022 at 13:49
  • Yes. I have tried User API Service mentioned in the answer. But It did not work for me. Jul 27, 2022 at 5:54
0

The User-ID can be retrieved from SDK. Please refer to class sap.ushell.services.UserInfo

0
0

Try this:

new sap.ushell.services.UserInfo().getId()
1
  • 1
    API reference explicitly warns NOT to call the constructor directly: "[new ...] must be called by the Unified Shell's container only, others MUST call sap.ushell.Container.getServiceAsync("UserInfo")." Something like this: stackoverflow.com/a/63524439/5846045 Aug 21, 2020 at 14:11
0

If you want to access the user detail when you are running your application in launchpad. then you can retrieve current user detail by adding following code snippet:

var userInfo = sap.ushell.Container.getService("UserInfo");
var email = userInfo.getEmail();

Then further detail about the user can be retrieved like email and fullname. See the API here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.