How to get current logged in user and department and email in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 09:57 PM
How to get current logged in user and department and email in ServiceNow
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 09:59 PM
Hi,
Use current.getUser() to get the current user object.
To get userID - getUserID()
For location - getLocation()
Ex. var user = gs.getUser(); //server side
var loc = user.getLocation();
Function/Method | Return Value | Usage |
---|---|---|
gs.getUser() | Returns a reference to the user object for the currently logged-in user. | var userObject = gs.getUser(); |
gs.getUserByID() | Returns a reference to the user object for the user ID (or sys_id) provided. | var userObject = gs.getUser().getUserByID('employee'); |
gs.getUserName() | Returns the User ID (user_name) for the currently logged-in user. e.g. 'employee' | var user_name = gs.getUserName(); |
gs.getUserDisplayName() | Returns the display value for the currently logged-in user. e.g. 'Joe Employee' | var userDisplay = gs.getUserDisplayName(); |
gs.getUserID() | Returns the sys_id string value for the currently logged-in user. | var userID = gs.getUserID(); |
getFirstName() | Returns the first name of the currently logged-in user. | var firstName = gs.getUser().getFirstName(); |
getLastName() | Returns the last name of the currently logged-in user. | var lastName = gs.getUser().getLastName(); |
getEmail() | Returns the email address of the currently logged-in user. | var email = gs.getUser().getEmail(); |
getDepartmentID() | Returns the department sys_id of the currently logged-in user. | var deptID = gs.getUser().getDepartmentID(); |
getCompanyID() | Returns the company sys_id of the currently logged-in user. | var companyID = gs.getUser().getCompanyID(); |
getCompanyRecord() | Returns the company GlideRecord of the currently logged-in user. | var company = gs.getUser().getCompanyRecord(); |
getLanguage() | Returns the language of the currently logged-in user. | var language = gs.getUser().getLanguage(); |
getLocation() | Returns the location of the currently logged-in user. | var location = gs.getUser().getLocation(); |
getDomainID() | Returns the domain sys_id of the currently logged-in user (only used for instances using domain separation). | var domainID = gs.getUser().getDomainID(); |
getDomainDisplayValue() | Returns the domain display value of the currently logged-in user (only used for instances using domain separation). | var domainName = gs.getUser().getDomainDisplayValue(); |
getManagerID() | Returns the manager sys_id of the currently logged-in user. | var managerID = gs.getUser().getManagerID(); |
getMyGroups() | Returns a list of all groups that the currently logged-in user is a member of. | var groups = gs.getUser().getMyGroups(); |
Mark this as Helpful/Correct, if Applicable.
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 10:00 PM
Hi ,
I am not sure what you're after or what's the purpose of your query.
Maybe go to filter navigator on left hand side
Type Logged In users
Then you can get the current logged in users.
You can then compare to sys_user table to find the other details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2022 10:03 PM
Hi
You can try to use "g_form" API to fetch values of currently logged in user to update the department field with,
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 07:11 AM
Hi,
Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.
Thanks,
Sandeep