GlideUser - Client

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 get user information.

The GlideUser methods and properties are accessed through a global object (g_user) that is only available in client scripts. GlideUser
  • contains name and role information about the current user.
  • is typically used in client scripts and UI policies but is also found in UI actions that run on the client.
  • cannot be used in business rules or UI actions that run on the server.
  • avoids the need for GlideRecord queries to get user information.

Session information about the current user and current user roles is contained in the client (web browser). All GlideUser methods except getClientData() access the session information that is available by default. The getClientData() method requires setup on the server and use of putClientData() to make session information available.

GlideUser - firstName

The current user's first name.

Table 1. Field
Name Type Description
firstName String Current user's first name.

alert('first name = ' + g_user.firstName);

GlideUser - lastName

The current user's last name.

Table 2. Field
Name Type Description
lastName String Current user's last name.
alert('last name = ' + g_user.lastName);

GlideUser - getClientData(string key)

Gets a session client value previously set with putClientData().

Session client data is a set of named strings that may be setup on the server (using putClientData()) that then may be used by client scripts (using getClientData()). Can be used during form load time to get information that the client script needs to make decisions about the form, for example, which fields should be visible.

Table 3. Parameters
Name Type Description
Key String Name of the client data to retrieve.
Table 4. Returns
Type Description
String Value of the client data.

var loginLanguage = g_user.getClientData("loginlanguage");

GlideUser - getFullName()

Returns the first and last name of the current user.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String The current user's full name.

var formalName = g_user.getFullName();

GlideUser - hasRole(String role)

Returns true if the current user has the specified or admin role.

Table 7. Parameters
Name Type Description
role String The role
Table 8. Returns
Type Description
Boolean Returns true if the current user has the specified or admin role, otherwise returns false.

var isAdmin = g_user.hasRole('admin');

GlideUser - hasRoleExactly(String role)

Returns true only if the current user has the specified role.

Table 9. Parameters
Name Type Description
role String The role
Table 10. Returns
Type Description
Boolean Returns true if the current user has the specified role.

var isItil = g_user.hasRoleExactly('itil');

GlideUser - hasRoleFromList(String roles)

Returns true if the current user has at least one of the specified roles or has the admin role.

Table 11. Parameters
Name Type Description
roles String Comma-separated list of roles
Table 12. Returns
Type Description
Boolean Returns true if the current has a role in the list or the admin role.

var isOK = g_user.hasRoleFromList("itil, maint");

GlideUser - hasRoles()

Returns true if the current user has any role.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
Boolean Returns true if the current user has at least one role.

var yesRole = g_user.hasRoles();

GlideUser - userID

The sys_id of the current user.

Table 15. Field
Name Type Description
userID String sys_id of the current user.

var userID = g_user.userID;
   alert('Current user ID = ' + userID);

GlideUser - userName

This property is the current user's username, for example gsmith02. It is not the user's name, for example George Smith.

Table 16. Field
Name Type Description
userName String The current user's username.
var userName = g_user.userName;
   alert('Current user = ' + userName);