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:
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:
Great work! You gave information is very useful for enhancing my knowledge. Keep updates your best...
ReplyDeletePrimavera Training in Chennai
Primavera Course in Chennai
Corporate Training in Chennai
Embedded System Course Chennai
Oracle Training in Chennai
Tableau Training in Chennai
Spark Training in Chennai
Excel Training in Chennai
Power BI Training in Chennai