Hi Everyone,

I am writing this blog to get login info into SAP UI5 application, where you can display User ID, FirstName, LastName, FullName, Email etc… in any of your SAP UI5 Apps.

Here is the sample code where you can fetch all the information into JSON format.

//Get User details once logged in

   //Get User details by using srv;

    var y = “/sap/bc/ui2/start_up”;

    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();

    xmlHttp.onreadystatechange = function() {

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

       var oUserData = JSON.parse(xmlHttp.responseText);

          console.log(oUserData);

       }

    };

    xmlHttp.open( “GET”, y, false );

    xmlHttp.send(null);

or we can also use JSON Model

oModel = new sap.ui.model.json.JSONModel();

oModel.loadData(“/sap/bc/ui2/start_up”);


Note: This will only run on SAP UI5 BSP application but not on local SAP UI5 application.

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

    1. Vinay Kumar Post author

      Hi Sridevi,

      This is not an ODATA service and it’s a JS file which gives the result, so it won’t work as ODATA request.

      this statement, y = “/sap/bc/ui2/start_up”; will look for this file in local system, which will not be there. So when you run this as BSP Application, that time it will look for this file in “<domain name>:<port>/sap/bc/ui2/start_up” path and it will search in gateway system.

      Hope this info helps.

      Thanks,

      Vinay

      (0) 
    1. Vinay Kumar Post author

      Hi Junju,

      You can try this following code by your server ip address and port (same as ODATA service)

      var oModel= new sap.ui.model.json.JSONModel();

      oModel.loadData(“http://<server host>:<server port>/sap/bc/ui2/start_up“);

      (0) 
    1. Vinay Kumar Post author

      You can try this following code by your server ip address and port (same as ODATA service)

      var oModel= new sap.ui.model.json.JSONModel();

      oModel.loadData(“http://<server host>:<server port>/sap/bc/ui2/start_up“);

      (0) 
  1. Junju Sowmya

    Hi Vinay,

    Thanks for the reply.

    If i give ” http://<myServerName&gt;:<port>/sap/bc/ui2/start_up “,i am getting 404-Not Found error.

    I want to get the username ,when i open the xs application from the browser.

    Your help would be highly appreciated

    Thanks,

    Sowmya

    (0) 
      1. Michal Holic

        Hello,
        I have the same problem. I don’t have ui2 installed, we don’t use ABAP. Our SAPUI5 application runs on Java AS and is authenticated via Java UME. Is there a way to get the username this way?

        (0) 
  2. Gilles Boutroux

    Hi Vinay thanks for your work

    I’m trying to use this

        //Get User details by using srv;

        var y = “/sap/bc/ui2/start_up”;

        var xmlHttp = null;

        xmlHttp = new XMLHttpRequest();

        xmlHttp.onreadystatechange = function() {

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

           var oUserData = JSON.parse(xmlHttp.responseText);

              console.log(oUserData);

           }

        };

        xmlHttp.open( “GET”, y, false );

        xmlHttp.send(null);

    the console.log show me that i get the data but then i try to set them into a JSON and then bind it to some table to display what i need.

    with this

    var oModel1 = new sap.ui.model.json.JSONModel();

                     oModel1.setData(oUserData);

                    sap.ui.getCore().setModel(aModel1,”test”);

    but i get errors depending from where i put this

    either oModel1 is not defined or oUseData is not defined
    end obviously i get no data into my table

    Any ideas?

    (0) 

Leave a Reply