{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1033,"path":"api-reference/server-api-reference/c_GlideSessionScopedAPI.md","title":"GlideSession - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideSession- Scoped\n\nThe scoped GlideSession API provides methods to find information about the current session.\n\nThere are no constructors for creating an instance of a scoped GlideSession object. Instead, use the getSession\\(\\) method of the scoped GlideSystem API.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## Scoped GlideSession - getClientData\\(String paramName\\)\n\nRetrieves a session client value previously set with putClientData\\(\\).\n\nUse this method to retrieve data values that were set using the putClientData\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|paramName|String|Name of the client data to retrieve.|\n\n|Type|Description|\n|----|-----------|\n|String|Client data.|\n\n```\nvar session = gs.getSession();\nsession.putClientData('test1', 'Harry');\nvar clientData = session.getClientData('test1');\ngs.info(clientData);\n```\n\nOutput:\n\n```\nHarry\n```\n\n## Scoped GlideSession - getClientIP\\(\\)\n\nReturns the client IP address.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|IP address.|\n\n```\nvar session = gs.getSession();\nvar addr = session.getClientIP();\ngs.info(addr);\n```\n\nOutput:\n\n```\n50.59.164.97\n```\n\n## Scoped GlideSession - getCurrentApplicationId\\(\\)\n\nReturns the application currently selected in the application picker.\n\nThis method requires admin privileges.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Currently selected application.|\n\n```\nvar session = gs.getSession();\nvar appID = session.getCurrentApplicationId();\ngs.info(appID);\n```\n\nOutput:\n\n```\nce05b9f32b840200c5244f74b4da1501\n```\n\n## Scoped GlideSession - getCurrentDomainID\\(\\)\n\nReturns the sys\\_id of the current domain for the logged-in user session.\n\nThe identifier that is returned depends on the domain type and the instantiation of that domain.\n\n-   If the user is configured in the global domain, and does not use the domain picker to switch domains, the method returns null.\n-   If the user uses the domain picker to switch to the global domain, the method returns the string \"global\".\n-   For all other domains, the method returns the sys\\_id of that domain.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the session domain of the current logged-in user. This is the same information that appears in the domain picker.|\n\nThis example shows the current sys\\_email record's domain being set to the user's session domain, if the user domain is global or null.\n\n```\n// Set domain based on parent record's domain\nsetDomain();\n\n// If the domain is global, set to user's domain\nif (current.sys_domain == 'global' || current.sys_domain.nil())\n   current.sys_domain = gs.getSession().getCurrentDomainID();\n\nfunction setDomain() {\n   if (current.target_table.nil())\n      return;\n\n   var d = new GlideRecord(current.target_table);\n   if (!d.isValid())\n      return;\n\n   if (!d.get('sys_id', current.instance))\n      return;\n\n   if (typeof(d.sys_domain) == 'object')\n      current.sys_domain = d.sys_domain;\n\n```\n\n## Scoped GlideSession - getLanguage\\(\\)\n\nReturns the session's language code.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Session's language code.|\n\n```\nvar session = gs.getSession();\nvar language = session.getLanguage();\ngs.info(language);\n```\n\nOutput:\n\n```\nen\n```\n\n## Scoped GlideSession - getSessionToken\\(\\)\n\nReturns the session token.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Session token.|\n\n```\nvar session = gs.getSession();\nvar token = session.getSessionToken();\ngs.info(token);\n```\n\nOutput:\n\n```\n4284b5372b840200c5244f74b4da15f2c3476cf7fcb6572afa4ef9d5e6d307a5fd9e1da7\n```\n\n## Scoped GlideSession - getTimeZoneName\\(\\)\n\nReturns the name of the session's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the session's time zone.|\n\n```\nvar session = gs.getSession();\nvar zoneName = session.getTimeZoneName();\ngs.info(zoneName);\n```\n\nOutput:\n\n```\nUS/Pacific\n```\n\n## Scoped GlideSession - getUrlOnStack\\(\\)\n\nReturns the URL on the stack. Returns null if the stack is empty.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|URL on the stack. Returns null if the stack is empty.|\n\n```\nvar session = gs.getSession();\nvar URL = session.getUrlOnStack();\ngs.info(URL);\n```\n\nOutput: line breaks added for clarity.\n\n```\nsys_app.do?sys_id=ce05b9f32b840200c5244f74b4da1501&sysparm_goto_url=sys_app.do\n%3Fsys_id%3Dce05b9f32b840200c5244f74b4da1501\n```\n\n## Scoped GlideSession - isImpersonating\\(\\)\n\nReturns true if the user is impersonating another user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_shv_tj5_xw\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates the user is impersonating another user.Possible values:\n\n-   true: User is impersonating.\n-   false: User isn't impersonating.\n\n</td></tr></tbody>\n</table>```\nvar isImpersonator = gs.getSession().isImpersonating();\ngs.info(isImpersonator);\n```\n\n## Scoped GlideSession - isInteractive\\(\\)\n\nReturns true if the session is interactive.\n\nAn 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_gjc_dpk_ls\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the session is interactive.Possible values:\n\n-   true: Session is interactive.\n-   false: Session isn't interactive.\n\n</td></tr></tbody>\n</table>```\nvar interActive = gs.getSession().isInteractive();\ngs.info(interActive);\n```\n\n## Scoped GlideSession - isLoggedIn\\(\\)\n\nReturns true if the user is logged in.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qhb_qpk_ls\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the user is logged inPossible values:\n\n-   true: User is logged in.\n-   false: User isn't logged in.\n\n</td></tr></tbody>\n</table>```\nvar session = gs.getSession();\nvar loggedIn = session.isLoggedIn();\ngs.info(loggedIn);\n```\n\nOutput:\n\n```\ntrue\n```\n\n## Scoped GlideSession - putClientData\\(String paramName, String paramValue\\)\n\nSets 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|paramName|String|Name of the client data to set.|\n|paramValue|String|Value of the client data.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar session = gs.getSession();\nsession.putClientData('test1', 'Harry');\nvar clientData = session.getClientData('test1');\ngs.info(clientData);\n```\n\nOutput:\n\n```\nHarry\n```\n\n"}}