XSJS - Session API

In this article we will show you an XSJS example to demonstrate – How to get session details in XSJS service.
Note: To check all the examples on XSJS, read the article SAP HANA XSJS Examples

Introduction:

XSJS provides Session APIs to enables access to the SAP HANA XS session, for example, to determine the language used in the session or check if a user has the privileges required to run an application.

You can use the XS JavaScript $.session API to request and check information about the currently open sessions.
For example:
$.session.getUsername() à returns the user name of the logged-on database user.
$.session.language à returns user language

Now, let us see a detail example of $.session API.

Example:

Create an XSJS file and paste the below code.

var body = '';
    body = JSON.stringify({
        "session": [{
     
          //$.session.getUsername() - Returns the user name of the logged-on database user
          "UserName": $.session.getUsername(),
     
         //$.session.language - Contains an empty string unless a language is explicitly set by the XS session layer.
         "Language": $.session.language,
     
         //$.session.getInvocationCount() - Returns the number of requests sent to the current session
         "InvocationCount": $.session.getInvocationCount(),
     
         //$.session.hasSystemPrivilege(privilegeName) - Checks whether the logged-on user has a specified system privilege
         "HasCreateSchemaPrivilege": $.session.hasSystemPrivilege("CREATE SCHEMA"),
     
         //$.session.getSecurityToken() - Returns unique session-specific token that could be used for XSRF prevention
         "SecurityToken": $.session.getSecurityToken()
        }]
    });
    $.response.contentType = 'application/json';
    $.response.setBody(body);
    $.response.status = $.net.http.OK;

Run XSJS Service:
Run the XSJS service and output will show the information as below:


Download Full Source Code:

Click here to download the full source code. Follow the steps mentioned in “How to Run.txt” to run it.

Reference:


Continue reading:

2 comments:

  1. Thanks For Your Information. We Sphinax InfoSystems are one of the leading ERP and SAP software development company in chennai. We have more than 7+ years of strong experience in ERP Application Development and SAP based services & support like SAP B1, SAP Hana, SAP R3 etc.. For More Info… http://sphinaxinfosystems.com/

    ReplyDelete