SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
Hadoop App
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Hadoop App
Stay Connected
Search Topics
Topic Index
XSA Overview
XS Overview
Hello World Example
XS OData Service
Core Data Service

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


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.


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.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.


SAP HANA XS JavaScript Reference

Continue reading:

Support us by sharing this article.

Explore More
Close X
Close X

4 thoughts on “SAP HANA XSJS – Session API

  1. Nico van der Linden says:

    Great Stuff!!! One question though, is there also an option to check if the user has a specific role? So just something like the “/$.session.hasSystemPrivilege(privilegeName)” but then for an Hana role?

  2. Krishna says:

    Hello Mate,
    THANKS SO MUCH for sharing this!
    Hana log volume disk is full and i cannot start it. can i create symbolic link
    of hdb00001 to other location and restart it??
    In a transformation I am using a field AMDP routine.
    Here is the scenario:
    Let’s say this is the input data
    name1 | Vienna | TBW
    name 2 | Berlin | QBW
    name 3 | Budapest | PBW
    I want to select the name and city depending on the system name. when the system is TBW then select this, else select the first line.
    The field should be filled like this:
    name1 | Vienna | TBW
    name 2 | Berlin | QBW
    Anyways great write up, your efforts are much appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

 © 2017 :, All rights reserved.  Privacy Policy