GlideSession - Scoped

The scoped GlideSession API provides a way to find information about the current session.

There are no constructors for creating an instance of a scoped GlideSession object. Instead, use the getSession() method of the scoped GlideSystem API.

Scoped GlideSession - getClientData(String paramName)

Gets a session client value previously set with putClientData().

This method is used in a client script to retrieve data values that were set by a server script that used the putClientData() method.

Table 1. Parameters
Name Type Description
paramName String Name of the client data to retrieve.
Table 2. Returns
Type Description
String The client data as a string.

var session = gs.getSession();
session.putClientData('test1', 'Harry');
var clientData = session.getClientData('test1');
gs.info(clientData);

Output:

Harry

Scoped GlideSession - getClientIP()

Returns the client IP address.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String The IP address.

var session = gs.getSession();
var addr = session.getClientIP();
gs.info(addr);

Output:

50.59.164.97

Scoped GlideSession - getCurrentApplicationId()

Returns the application currently selected in the application picker.

This method requires admin privileges.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String The currently selected application.

var session = gs.getSession();
var appID = session.getCurrentApplicationId();
gs.info(appID);

Output:

ce05b9f32b840200c5244f74b4da1501

Scoped GlideSession - getLanguage()

Returns the session's language code.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String The session's language code.

var session = gs.getSession();
var language = session.getLanguage();
gs.info(language);

Output:

en

Scoped GlideSession - getSessionToken()

Returns the session token.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
String The session token.

var session = gs.getSession();
var token = session.getSessionToken();
gs.info(token);

Output:

4284b5372b840200c5244f74b4da15f2c3476cf7fcb6572afa4ef9d5e6d307a5fd9e1da7

Scoped GlideSession - getTimeZoneName()

Returns the name of the session's time zone.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
String The name of the session's time zone.

var session = gs.getSession();
var zoneName = session.getTimeZoneName();
gs.info(zoneName);

Output:

US/Pacific

Scoped GlideSession - getUrlOnStack()

Returns the URL on the stack. Returns null if the stack is empty.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
String The URL. Returns null if the stack is empty.

var session = gs.getSession();
var URL = session.getUrlOnStack();
gs.info(URL);

Output: line breaks added for clarity.

sys_app.do?sys_id=ce05b9f32b840200c5244f74b4da1501&sysparm_goto_url=sys_app.do
%3Fsys_id%3Dce05b9f32b840200c5244f74b4da1501

Scoped GlideSession - isImpersonating()

Returns true if the user is impersonating another user.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
Boolean Returns true if the user is impersonating another user; otherwise, returns false.
var isImpersonator = gs.getSession().isImpersonating();
gs.info(isImpersonator);

Scoped GlideSession - isInteractive()

Returns true if the session is interactive.

An interactive session is one that involves an end-user interacting with a user interface that then retrieves information from a server. An example of this type of session is when a user logs in using the log-in screen or uses a form to query a data store. A non-interactive session is one that only involves programmatic interaction with a server such as a SOAP request to retrieve data.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
Boolean True if the session is interactive.
var interActive = gs.getSession().isInteractive();
gs.info(interActive);

Scoped GlideSession - isLoggedIn()

Returns true if the user is logged in.

Table 19. Parameters
Name Type Description
None
Table 20. Returns
Type Description
Boolean True if the user is logged in.

var session = gs.getSession();
var loggedIn = session.isLoggedIn();
gs.info(loggedIn);

Output:

true

Scoped GlideSession - putClientData(String paramName, String paramValue)

Sets a session client value that can be retrieved with getClientData(). This method is used in a server side script that runs when a form is created.

Table 21. Parameters
Name Type Description
paramName String Name of the client data to set.
paramValue String Value of the client data.
Table 22. Returns
Type Description
void

var session = gs.getSession();
session.putClientData('test1', 'Harry');
var clientData = session.getClientData('test1');
gs.info(clientData);

Output:

Harry