Skip to Content
Author's profile photo Karthik Arjun

Get user name from server login page

Hi All,

As I faced few issues while implement my project in SAP system. I had noted down it here, I hope it may be useful to you.

Scenario:

1. I am using Server login page to access my SAP GW service
2. I need username to display it in my next screen

Solution:

 

var oUserData = "";

var usernameService = "/sap/bc/ui2/start_up"; //Standard service

var HttpRequest = "";

HttpRequest = new XMLHttpRequest();

HttpRequest.onreadystatechange = function() {

if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {

oUserData = JSON.parse(xmlHttp.responseText);

}

};

HttpRequest.open( "GET", usernameService, false );

var usernameFinal = oUserData.id

Thanks, Karthik A

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      This is exactly what I was looking for! Thank you so much Karthik!
       

      Author's profile photo Meenakshi Raina
      Meenakshi Raina

      Hi Karthik,

      Thanks for sharing a detailed blog on this issue. I tried the same code in my onInit function, but I am getting an error - usernameFinal = undefined, oUserData = "".

      Can you please help me with it.

      Author's profile photo Rudramani Pandey
      Rudramani Pandey

      Were you able to resolve this issue?

      Author's profile photo Fotios Tragopoulos
      Fotios Tragopoulos

      It returns undefined to me too.