{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1045,"path":"api-reference/server-api-reference/c_GlideUserScopedAPI.md","title":"GlideUser - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideUser- Scoped\n\nThe GlideUser API provides methods to access information about the current user and current user roles.\n\nUsing the GlideUser API avoids the need to use the slower GlideRecord queries to get user information.\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 GlideUser - getCompanyID\\(\\)\n\nReturns the current user's company sys\\_id.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Company sys\\_id.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getCompanyID());\n```\n\n## Scoped GlideUser - getDisplayName\\(\\)\n\nReturns the current user's display name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|User's display name|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getDisplayName());\n```\n\n## Scoped GlideUser - getEmail\\(\\)\n\nReturns the user's email address.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|User's email address.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getEmail());\n```\n\n## Scoped GlideUser - getFirstName\\(\\)\n\nReturns the user's first name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|User's first name.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getFirstName());\n```\n\n## Scoped GlideUser - getID\\(\\)\n\nGets the sys\\_id of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|User's sys\\_id.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getID());\n```\n\n## Scoped GlideUser - getLastName\\(\\)\n\nReturns the user's last name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|User's last name.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getLastName());\n```\n\n## Scoped GlideUser - getName\\(\\)\n\nReturns the user ID, or login name, of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|User ID or login name.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getName());\n```\n\n## Scoped GlideUser - getPreference\\(String name\\)\n\nGets the specified user preference value for the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Name of the preference.|\n\n|Type|Description|\n|----|-----------|\n|String|Preference value.|\n\n```\nvar currentUser = gs.getUser(); \ncurrentUser.savePreference(­'myPref','red'); \ngs.info(currentUser.getPreference(­'myPref'));\n```\n\n## Scoped GlideUser - getRoles\\(\\)\n\nReturns a list of roles that includes explicitly granted roles, inherited roles, and roles acquired by group membership.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|List of all roles available to the user|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getRoles());\n```\n\n## Scoped GlideUser - getTimeZoneLabel\\(\\)\n\nReturns the current user's time zone label in the current user's preferred language.\n\nFor more information about setting a user's preferred language, see [User specific language](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_UserSpecificLanguage.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The current user's time zone label.|\n\nThis example shows how to return the current user's time zone label in their preferred language.\n\n```\ngs.info(gs.getUser().getTimeZoneLabel());\n```\n\nOutput:\n\n```\nEurope/Dublin\n```\n\n## Scoped GlideUser - getTimeZoneLabelLang\\(String language\\)\n\nReturns the current user's time zone label in the specified language.\n\n<table id=\"table_hlp_hw2_bdc\" 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\nlanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nLanguage to use for the time zone label. Located in the ID column of the Language \\[sys\\_language\\] table. If a valid language isn't provided, the time zone label is returned in English.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|The current user's time zone label.|\n\nThis example shows how to return the current user's time zone label in a specified language.\n\n```\ngs.info(gs.getUser().getTimeZoneLabelLang(\"es\")); //Spanish\ngs.info(gs.getUser().getTimeZoneLabelLang(\"ja\")); //Japanese\ngs.info(gs.getUser().getTimeZoneLabelLang(\"jksjsjks\")); //invalid\n```\n\nOutput:\n\n```\nEuropa/Dublín\nヨーロッパ/ダブリン\nEurope/Dublin\n```\n\n## Scoped GlideUser - getUserRoles\\(\\)\n\nReturns the list of roles explicitly granted to the user.\n\nUnlike the getRoles\\(\\) method, this method does not return roles the user inherits or roles acquired from group membership.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|List of roles explicitly assigned to the user.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getUserRoles());\n```\n\n## Scoped GlideUser - hasRole\\(String role\\)\n\nDetermines if the current user has the specified role.\n\n|Name|Type|Description|\n|----|----|-----------|\n|role|String|Role to check.|\n\n<table id=\"table_ik4_5k4_1r\" 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 has the specified role.Possible values:\n\n-   true: User has the specified role.\n-   false: User doesn't have the specified role.\n\n</td></tr></tbody>\n</table>```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.hasRole('admin'));\n```\n\n## Scoped GlideUser - isMemberOf\\(String group\\)\n\nDetermines if the current user is a member of the specified group.\n\n|Name|Type|Description|\n|----|----|-----------|\n|group|String|Sys\\_id or name of the group to check.|\n\n<table id=\"table_ock_gl4_1r\" 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 a member of the specified group.Possible values:\n\n-   true: User is a member of the group.\n-   false: User isn't a member of the group.\n\n</td></tr></tbody>\n</table>The following example checks if the current user is a member of the Capacity Mgmt group.\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.isMemberOf('Capacity Mgmt'));\n```\n\nOutput:\n\n```\nfalse\n```\n\n## Scoped GlideUser - savePreference\\(String name, String value\\)\n\nSaves a user preference value to the database.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Preference to save.|\n|value|String|Preference value.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar currentUser = gs.getUser(); \ncurrentUser.savePreference('myPref','red'); \ngs.info(currentUser.getPreference('myPref'));\n```\n\n"}}