{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":194,"path":"api-reference/c_GlideUserAPI.md","title":"GlideUser - Client","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideUser - Client\n\nThe GlideUser API provides methods that access information about the current user and current user roles. Using this API avoids the need to use the slower GlideRecord queries to get user information.\n\nGlideUser methods and properties are accessed through a global object \\(`g_user`\\) that is only available in client scripts.\n\nThis API:\n\n-   contains name and role information about the current user.\n-   is typically used in client scripts and UI policies but is also found in UI actions that run on the client.\n-   cannot be used in business rules or UI actions that run on the server.\n\nSession information about the current user and current user roles is contained in the client \\(web browser\\). All GlideUser methods except getClientData\\(\\) access the session information that is available by default. The getClientData\\(\\) method requires setup on the server and use of the putClientData\\(\\) method to make session information available.\n\nFor information on using client-side scripts, see [Introduction to Client-side Scripting](https://developer.servicenow.com/dev.do#!/learn/courses/sandiego/app_store_learnv2_scripting_rome_scripting_in_servicenow/app_store_learnv2_scripting_rome_client_side_scripting/app_store_learnv2_scripting_rome_introduction_to_client_side_scripting).\n\n**Parent Topic:**[Client API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/api-client.md)\n\n## GlideUser - firstName\n\nThe current user's first name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|firstName|String|Current user's first name.|\n\n```\nalert('first name = ' + g_user.firstName);\n```\n\n## GlideUser - getClientData\\(String key\\)\n\nReturns a client value set using setClientData\\(\\) or GlideSession -- putClientData\\(\\).\n\nSession client data is a set of named strings that may be setup on the server using [GlideSession -- putClientData\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSessionScopedAPI.md). You can use getClientData\\(\\) during form load time to get information that the client script needs to make decisions about the form. For example, to identify which fields should be visible.\n\nSee also [GlideForm](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/c_GlideFormAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Name of the client data to retrieve.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the client data.|\n\n```\nvar loginLanguage = g_user.getClientData(\"loginlanguage\");\n```\n\n## GlideUser - getFullName\\(\\)\n\nReturns the first and last name of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The current user's full name.|\n\n```\nvar formalName = g_user.getFullName();\n```\n\n## GlideUser - hasRole\\(String role, Boolean includeDefaults\\)\n\nReturns true if the current user has the specified role or the admin role.\n\n<table id=\"table_p1w_4m3_ws\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nrole\n\n</td><td>\n\nString\n\n</td><td>\n\nRole to check.\n\n</td></tr><tr><td>\n\nincludeDefaults\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to include default roles, such as snc\\_internal and snc\\_external, in the request. For additional information on roles, see [Exploring user administration](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/exploring-user-administration.md). Default: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Boolean|Returns true if the current user has the specified role or the admin role; otherwise returns false.|\n\n```\nvar isInternal = g_user.hasRole('snc_internal', true);\n```\n\n```\nvar isItil = g_user.hasRole('itil');\n```\n\n## GlideUser - hasRoleExactly\\(String role, Boolean includeDefaults\\)\n\nDetermines whether the current user has the specified role.\n\n<table id=\"table_r53_hn3_ws\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nincludeDefaults\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to include default roles, such as snc\\_internal and snc\\_external, in the request. For additional information on roles, see [Explicit roles](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/explicit-roles.md).\n\nDefault: false\n\n</td></tr><tr><td>\n\nrole\n\n</td><td>\n\nString\n\n</td><td>\n\nRole to check.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Boolean|Returns true if the current user has the specified role.|\n\n```\nvar isInternal = g_user.hasRoleExactly('snc_internal', true);\n```\n\n```\nvar isItil = g_user.hasRoleExactly('itil');\n```\n\n## GlideUser - hasRoleFromList\\(String roles, Boolean includeDefaults\\)\n\nReturns true if the current user has at least one of the specified roles or has the admin role.\n\n<table id=\"table_oxf_wn3_ws\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nroles\n\n</td><td>\n\nString\n\n</td><td>\n\nComma-separated list of roles to check\n\n</td></tr><tr><td>\n\nincludeDefaults\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to include default roles, such as snc\\_internal and snc\\_external, in the request. For additional information on roles, see [Exploring user administration](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/exploring-user-administration.md). Default: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Boolean|Returns true if the current user has a role in the list or the admin role.|\n\n```\nvar isOK = g_user.hasRoleFromList(\"itil, maint\");\n```\n\n```\nvar isOK = g_user.hasRoleFromList(\"itil, maint, snc_internal\", true);\n```\n\n## GlideUser - hasRoles\\(Boolean includeDefaults\\)\n\nReturns true if the current user has any role.\n\n<table id=\"table_ups_k43_ws\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nincludeDefaults\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to include default roles, such as snc\\_internal and snc\\_external, in the request. For additional information on roles, see [Exploring user administration](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/exploring-user-administration.md). Default: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Boolean|Returns true if the current user has at least one role.|\n\n```\nvar yesRole = g_user.hasRoles();\n```\n\n```\nvar yesRole = g_user.hasRoles(true);\n```\n\n## GlideUser - lastName\n\nThe current user's last name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|lastName|String|Current user's last name.|\n\n```\nalert('last name = ' + g_user.lastName);\n```\n\n## GlideUser - setClientData\\(String key, String value\\)\n\nSets a client value that you can retrieve using getClientData\\(\\).\n\nSee also [GlideForm](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/c_GlideFormAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Name of the client data to store as a key.|\n|value|Number|Value to assign to the key.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nfunction onSubmit() {\n\t\n\tif (!g_user.getClientData('keyName')) {\n\t\tvar now_GR = new GlideRecord('incident');\n\t\tnow_GR.addActiveQuery();\n\t\tnow_GR.setLimit(1);\n\t\tnow_GR.query(cb);\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nfunction cb(now_GR) {\n\t// <insert glide operation >\n\tg_user.setClientData('keyName', now_GR.getValue('<number>'));\n\tg_form.submit();\t\n}\n```\n\n## GlideUser - userName\n\nThe current user's username, for example gsmith02. It is not the user's name, for example George Smith.\n\n|Name|Type|Description|\n|----|----|-----------|\n|userName|String|Current user's username.|\n\n```\nvar userName = g_user.userName;\n   alert('Current user = ' + userName);\n```\n\n## GlideUser - userID\n\nReturns the sys\\_id of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|userID|String|Sys\\_id of the current user.|\n\n```\nvar userID = g_user.userID;\n   alert('Current user ID = ' + userID);\n```\n\n"}}