GlideUser - Global

The GlideUser API provides access to information about the current user and current user roles.

Using the GlideUser API avoids the need to use the slower GlideRecord queries to obtain user information.

GlideUser - getCompanyID()

Returns the current user's company sys_id.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
String Company sys_id

Scoped equivalent

To use the getCompanyID() method in a scoped application, use the corresponding scoped method: Scoped GlideUser - getCompanyID().

var currentUser = gs.getUser(); 
gs.info(currentUser.getCompanyID());

GlideUser - getDisplayName()

Returns the current user's display name.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String User's display name

Scoped equivalent

To use the getDisplayName() method in a scoped application, use the corresponding scoped method: Scoped GlideUser - getDisplayName().

var currentUser = gs.getUser(); 
gs.info(currentUser.getDisplayName());

GlideUser - getDomainDisplayValue()

Returns the display value of the user's session domain.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String The display value of the user's session domain.

Scoped equivalent

There is no workaround for scoped applications.


    

Optional example explanation

var currentUser = gs.getUser(); 
gs.info(currentUser.getDomainDisplayValue());

Output:

GlideUser - getEmail()

Returns the user's email address.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String User's email address
var currentUser = gs.getUser(); 
gs.info(currentUser.getEmail());

GlideUser - getFirstName()

Returns the user's first name.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
String User's first name
var currentUser = gs.getUser(); 
gs.info(currentUser.getFirstName());

GlideUser - getID

Returns the sys_id of the current user.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
String User's sys_id

Scoped equivalent

To use the getID() method in a scoped application, use the corresponding scoped method: Scoped GlideUser - getID().

var currentUser = gs.getUser(); 
gs.info(currentUser.getID());

GlideUser - getLastName()

Returns the user's last name.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
String User's last name
var currentUser = gs.getUser(); 
gs.info(currentUser.getLastName());

GlideUser - getMyGroups()

Returns an iterator containing the list of all groups to which the user belongs. Only active groups are returned.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
iterator A list of sys_ids for the active groups to which the user belongs.

Scoped equivalent

There is no scoped equivalent for this method.

An example

var groupsArray = gs.getUser().getMyGroups().toArray();
gs.info(groupsArray[0]);

Output:cfcbad03d711110050f5edcb9e61038f

GlideUser - getName()

Returns the user ID, or login name, of the current user.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
String User ID

Scoped equivalent

To use the getName() method in a scoped application, use the corresponding scoped method: Scoped GlideUser - getName().

var currentUser = gs.getUser(); 
gs.info(currentUser.getName());

GlideUser - getRoles()

Returns a list of roles that includes explicitly granted roles, inherited roles, and roles acquired by group membership.

Table 19. Parameters
Name Type Description
None
Table 20. Returns
Type Description
Array List of all roles available to the user
var currentUser = gs.getUser(); 
gs.info(currentUser.getRoles());

GlideUser - getUserRoles()

Returns the list of roles explicitly granted to the user.

Table 21. Parameters
Name Type Description
None
Table 22. Returns
Type Description
Array List of roles explicitly assigned to the user
var currentUser = gs.getUser(); 
gs.info(currentUser.getUserRoles());

GlideUser - hasRole(String role)

Determines if the current user has the specified role.

Table 23. Parameters
Name Type Description
role String Role to check
Table 24. Returns
Type Description
Boolean True if the user has the role.

Scoped equivalent

To use the hasRole() method in a scoped application, use the corresponding scoped method: Scoped GlideUser - hasRole(String role).

var currentUser = gs.getUser(); 
gs.info(currentUser.hasRole('admin'));

Output:

GlideUser - isMemberOf(String group)

Determines if the current user is a member of the specified group.

Table 25. Parameters
Name Type Description
group String Group to check
Table 26. Returns
Type Description
Boolean True if the user is a member of the group.

Scoped equivalent

To use the isMemberOf() method in a scoped application, use the corresponding scoped method: Scoped GlideUser - isMemberOf(String group).

var currentUser = gs.getUser(); 
gs.info(currentUser.isMemberOf(­'Capacity Mgmt'));