cancel
Showing results for 
Search instead for 
Did you mean: 

Get Logged user SAP Gaetway - SAPUI5

rubens12
Participant
0 Kudos

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?

saurabh_vakil
Active Contributor
0 Kudos

Are you running the project locally in Eclipse? Or are you deploying it to the ABAP repository on the getaway and running it on the server?

Accepted Solutions (1)

Accepted Solutions (1)

rubens12
Participant
0 Kudos

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);
            },

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ruben,

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

Regards

Madhu

rubens12
Participant
0 Kudos

The problem was the url, now it's working