Skip to Content

Get Logged user SAP Gaetway - SAPUI5

I an trying get the logged Sap Gateway logged user.

The code bellow is in my controler

onInit : function (evt) {
	var oUserData;
    var y = "/sap/bc/ui2/start_up";
    var xmlHttp = null;
    xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            oUserData = JSON.parse(xmlHttp.responseText);
            alert(oUserData);
        }else{alert("fail");}
    };
    xmlHttp.open("GET", y, false);
    xmlHttp.send(null);
		},

When I run my application in eclipse it's also show the alert "fail". What's happen? It's wrong?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 20, 2017 at 11:32 AM

    Now it's working

    Below is my new code

    onInit : function (evt) {
            var oUserData;
            var y = "http://<your_gateway_system>:<port>/sap/bc/ui2/start_up";
            var xmlHttp = null;
            xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    oUserData = JSON.parse(xmlHttp.responseText);
                   alert(oUserData["fullName"]);
                }
            };
            xmlHttp.open("GET", y, false);
            xmlHttp.send(null);
                },
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 19, 2017 at 08:02 PM

    Hi Ruben,

    Take off the - else{alert("fail");} and try .

    Regards

    Madhu

    Add comment
    10|10000 characters needed characters exceeded