{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":771,"path":"api-reference/server-api-reference/GUserAPI.md","title":"GlideUser - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideUser- Global\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 obtain 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## 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 equivalent\n\nTo use the getCompanyID\\(\\) method in a scoped application, use the corresponding scoped method: [getCompanyID\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## 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 equivalent\n\nTo use the getDisplayName\\(\\) method in a scoped application, use the corresponding scoped method: [getDisplayName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - getDomainDisplayValue\\(\\)\n\nReturns the display value of the user's session domain.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The display value of the user's session domain.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getDomainDisplayValue());\n```\n\n### Scoped equivalent\n\nThere is no workaround for scoped applications.\n\n## GlideUser - getDomainID\\(\\)\n\nReturns the identifier of the user's current session domain.\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|Domain identifier.|\n\n```\nvar domain = new GlideRecord('domain');\ndomain.get(gs.getUser().getDomainID());\ngs.info(domain.name);\n```\n\n## 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 equivalent\n\nTo use the getEmail\\(\\) method in a scoped application, use the corresponding scoped method: [getEmail\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - getFirstName\\(\\)\n\nReturns the user's first name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_njs_zb3_xz\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject/String\n\n</td><td>\n\nUser's first name.**Note:** The data type for the returned value is object, however, the information is returned as a string.\n\n</td></tr></tbody>\n</table>```\nvar currentUser = gs.getUser(); \nvar userName = currentUser.getFirstName();\ngs.info('User First Name: + userName);\ngs.info('Data type: ' + typeof userName);\n```\n\n```\n*** Script: User First Name: John\n*** Script: Data type: object\n```\n\n### Scoped equivalent\n\nTo use the getFirstName\\(\\) method in a scoped application, use the corresponding scoped method: [getFirstName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - getID\n\nReturns 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 equivalent\n\nTo use the getID\\(\\) method in a scoped application, use the corresponding scoped method: [getID\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - getLastName\\(\\)\n\nReturns the user's last name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_bgq_1g3_xz\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject/String\n\n</td><td>\n\nUser's last name.**Note:** The data type for the returned value is object, however, the information is returned as a string.\n\n</td></tr></tbody>\n</table>```\nvar currentUser = gs.getUser(); \nvar userName = currentUser.getLastName();\ngs.info('User Last Name: + userName);\ngs.info('Data type: ' + typeof userName);\n```\n\n```\n*** Script: User Last Name: Smith\n*** Script: Data type: object\n```\n\n### Scoped equivalent\n\nTo use the getLastName\\(\\) method in a scoped application, use the corresponding scoped method: [getLastName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - getMyGroups\\(\\)\n\nReturns an iterator containing the list of all groups to which the user belongs. Only active groups are returned.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|iterator|A list of sys\\_ids for the active groups to which the user belongs.|\n\nThe following example shows how to return a list of groups the user belongs to.\n\n```\nvar groupsArray = gs.getUser().getMyGroups().toArray();\ngs.info(groupsArray[0]);\n```\n\nOutput:\n\n```\ncfcbad03d711110050f5edcb9e61038f\n```\n\n### Scoped equivalent\n\nThere is no scoped equivalent for this method.\n\n## 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|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getName());\n```\n\n### Scoped equivalent\n\nTo use the getName\\(\\) method in a scoped application, use the corresponding scoped method: [getName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - getRoles\\(\\)\n\nReturns a list of roles associated with the user. Includes explicitly granted roles, inherited roles, and roles acquired by group membership.\n\n**Note:** Use hasRole\\(\\) instead of getRoles\\(\\) if any session-related role changes occur, like role masking or role delegation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|Comma-separated list of user roles.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.getRoles());\n```\n\nOutput:\n\n```\nadmin,hr_fulfiller,itsa_fulfiller,security_admin\n```\n\n### Scoped equivalent\n\nTo use the getRoles\\(\\) method in a scoped application, use the corresponding scoped method: [getRoles\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## 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## GlideUser - getTimeZoneLabelLang\\(String language\\)\n\nReturns the current user's time zone label in the specified language.\n\n<table id=\"table_bkc_4w2_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## GlideUser - getUserByID \\(String id\\)\n\nReturns the user object associated with the passed-in user ID \\(sys\\_id in sys\\_user\\) or user\\_name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|id|String|Unique ID \\(sys\\_id\\) or user\\_name of the desired user record.|\n\n|Type|Description|\n|----|-----------|\n|Object|User object associated with the specified sys\\_id or user\\_name.|\n\nExample using user name \\(user\\_name\\).\n\n```\nvar currentUser = gs.getUser();\ngs.info(currentUser.getFirstName()); // print the first name of the logged in user\nvar newUser = currentUser.getUserByID('abel.tuter'); // fetch a different user using the user_name field\ngs.info(newUser.getFirstName()); // print the first name of the Abel Tuter user \n\n```\n\nExample using user ID \\(sys\\_id\\).\n\n```\nvar currentUser = gs.getUser();\ngs.info(currentUser.getFirstName()); // print the first name of the logged in user\nvar newUser = currentUser.getUserByID('62826bf03710200044e0bfc8bcbe5df1'); // fetch Abel Tuter user using sys_id from sys_user record\ngs.info(newUser.getFirstName()); // print the first name of the Abel Tuter user \n\n```\n\n## GlideUser - getUserRoles\\(\\)\n\nReturns the list of roles explicitly granted to the user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qkf_xnm_xz\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject/String\n\n</td><td>\n\nList of comma-separated roles explicitly assigned to the user.**Note:** The data type for the returned value is object, however, the information is returned as a string.\n\n</td></tr></tbody>\n</table>```\nvar currentUser = gs.getUser(); \nvar userRoles = currentUser.getUserRoles();\ngs.info('User Roles: ' + userRoles);\ngs.info('Data type: ' + typeof userRoles);\n```\n\n```\n*** Script: User Roles: ,admin,security_admin\n*** Script: Data type: object\n```\n\n### Scoped equivalent\n\nTo use the getUserRoles\\(\\) method in a scoped application, use the corresponding scoped method: [getUserRoles\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - hasRole\\(String role\\)\n\nDetermines if the current user has the specified role.\n\n**Note:** Use hasRole\\(\\) instead of getRoles\\(\\) if any session-related role changes occur, like role masking or role delegation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|role|String|Role to check|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the user has the role.|\n\n```\nvar currentUser = gs.getUser(); \ngs.info(currentUser.hasRole('admin'));\n```\n\n### Scoped equivalent\n\nTo use the hasRole\\(\\) method in a scoped application, use the corresponding scoped method: [hasRole\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n## GlideUser - isExplicitMemberOf\\(String group\\)\n\nDetermines if the current user is an explicit member of the specified group. Only active groups are evaluated by this method.\n\nThe isMemberOf\\(\\) method returns true for a parent group if the user is a member of the child group. Use this method if you only want to return true for parent groups.\n\n|Name|Type|Description|\n|----|----|-----------|\n|group|String|Sys\\_id of the user group to check.|\n\n<table id=\"table_m1q_4lm_xz\" 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 current user is an explicit member of the specified group.\n\n Valid values:\n\n-   true: The current user is an explicit member of the specified group.\n-   false: The current user is not an explicit member of the specified group.\n\n</td></tr></tbody>\n</table>The following example shows how to check if the current user is an explicit member of the specified group.\n\n```\nvar isExplMem = gs.getUser().isExplicitMemberOf('b8ef24616fc331003b3c498f5d3ee434');\ngs.info(isExplMem);\n```\n\nOutput:\n\n```\nfalse\n```\n\n### Scoped equivalent\n\nThere is no scoped equivalent for this method.\n\n## GlideUser - isMemberOf\\(String group\\)\n\nDetermines if the current user is a member of the specified group. Only active groups are evaluated by this method.\n\nThis method returns true for a parent group if the user is a member of the child group. Use the isExplicitMemberOf\\(\\) if you only want to return true for parent groups.\n\n|Name|Type|Description|\n|----|----|-----------|\n|group|String|Sys\\_id or name of the group to check.|\n\n<table id=\"table_m1q_4lm_xz\" 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 equivalent\n\nTo use the isMemberOf\\(\\) method in a scoped application, use the corresponding scoped method: [isMemberOf\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md).\n\n"}}