cancel
Showing results for 
Search instead for 
Did you mean: 

Display Username in SAPUI5 Interface on HANA

Former Member
0 Kudos

Hi Experts,

I am trying out the Application Header control in SAPUI5. I wanted to display the Application User that has logged in to Application to be displayed in the control. I tried to find the answer here but all the replies are specific to SAPUI5 on Netweaver, however I was wondering how to achieve this on the HANA XS Platform.

Any help would be appreciated.

Thanks and Regards,

Shreepad Patil

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks Angel and Philip,

I was also thinking in similar direction, but still I am not sure how to consume this XSJS service in the UI5 page.

In the UI5 view I have something as

var user = ???

oAppHeader.setUserName(user);

Can you please tell me how to assign the response from the XSJS to the user variable?

0 Kudos

This is a snippet of a function that we had with changes for your oAppHeader:


      jQuery.ajax({

        url : <path to xsjs script>,

        async : false,

        method : "GET",

        dataType : 'json',

        success : function(myJSON) {

          oAppHeader.setUserName = myJSON.username;

        },

        error : function() {

          oAppHeader.setUserName =  "";

        },

      });

former_member182650
Contributor
0 Kudos

Hi,

ApplicationHeader element has username attribute:

SAPUI5 SDK - Demo Kit

Also Shell element:

SAPUI5 SDK - Demo Kit

Kind regards

SandipAgarwalla
Active Contributor
0 Kudos

Apart from what Angel has suggested, I would suggest you use HANA Ui Integration services.

There are standard services for getting User/Role/Navigation information from the HANA XS.

Answers (2)

Answers (2)

0 Kudos

We simply created a serverside javascript (xsjs) file that did the following and used the $.session.getUsername api call that is available and retrieved that in the UI5 code:


var body = '';

body = {

  "username" : $.session.getUsername()

  };

body = JSON.stringify(body);

$.response.status = $.net.http.OK;

$.response.content = 'application/json';

$.response.setBody(body);

former_member182650
Contributor
0 Kudos

Hi Shreepad,

Take a look to this post: http://scn.sap.com/thread/3474318


You could substitute PortalUser by a custom entity in Hana XS returning a JSON with user logged in HANA:



$.response.contentType = "application/json";

var output = "";

var conn = $.db.getConnection();

var pstmt = conn.prepareStatement( "SELECT CURRENT_USER FROM DUMMY" );

var rs = pstmt.executeQuery();

if (!rs.next()) {

$.response.setBody( "Failed to retrieve data" );

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;

}

else {

output = '{ "user": "' + rs.getString(1) + '"}';

}

rs.close();

pstmt.close();

conn.close();

$.response.setBody(output);


Kind regards