How to get current logged in user and department and email in ServiceNow

srinivas snow26
Giga Contributor

How to get current logged in user and department and email in ServiceNow

6 REPLIES 6

Sourabh26
Giga Guru

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/MethodReturn ValueUsage
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

Kifrez
Kilo Guru

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.

Community Alums
Not applicable

Hi @srinivas snow2287 ,

You can try to use "g_form" API to fetch values of currently logged in user to update the department field with,

 

find_real_file.png

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Community Alums
Not applicable

Hi,

Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.

Thanks,
Sandeep