The GlideUser API provides methods that access information about the current user and current user roles. Using this API avoids the need to use the slower GlideRecord queries to get user information.

GlideUser methods and properties are accessed through a global object (g_user) that is only available in client scripts.

This API:
  • 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.

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 the putClientData() method to make session information available.

For information on using client-side scripts, see Introduction to Client-side Scripting.

GlideUser - firstName

The current user's first name.

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

Example

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

GlideUser - getClientData(String key)

Returns a client value set using setClientData() or GlideSession -- putClientData().

Session client data is a set of named strings that may be setup on the server using GlideSession -- putClientData(). You can use getClientData() during form load time to get information that the client script needs to make decisions about the form. For example, to identify which fields should be visible.

See also GlideForm.

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

Example

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

GlideUser - getFullName()

Returns the first and last name of the current user.

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

Example

var formalName = g_user.getFullName();

GlideUser - hasRole(String role, Boolean includeDefaults)

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

Table 6. Parameters
Name Type Description
role String Role to check.
includeDefaults Boolean Optional. Flag that indicates whether to include default roles, such as snc_internal and snc_external, in the request. For additional information on roles, see Exploring user administration.

Default: false

Table 7. Returns
Type Description
Boolean Returns true if the current user has the specified role or the admin role; otherwise returns false.

Example

var isInternal = g_user.hasRole('snc_internal', true);

Example

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

GlideUser - hasRoleExactly(String role, Boolean includeDefaults)

Determines whether the current user has the specified role.

Table 8. Parameters
Name Type Description
includeDefaults Boolean Optional. Flag that indicates whether to include default roles, such as snc_internal and snc_external, in the request. For additional information on roles, see

Explicit roles.

Default: false

role String Role to check.
Table 9. Returns
Type Description
Boolean Returns true if the current user has the specified role.

Example

var isInternal = g_user.hasRoleExactly('snc_internal', true);

Example

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

GlideUser - hasRoleFromList(String roles, Boolean includeDefaults)

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

Table 10. Parameters
Name Type Description
roles String Comma-separated list of roles to check
includeDefaults Boolean Optional. Flag that indicates whether to include default roles, such as snc_internal and snc_external, in the request. For additional information on roles, see Exploring user administration.

Default: false

Table 11. Returns
Type Description
Boolean Returns true if the current user has a role in the list or the admin role.

Example

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

Example

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

GlideUser - hasRoles(Boolean includeDefaults)

Returns true if the current user has any role.

Table 12. Parameters
Name Type Description
includeDefaults Boolean Optional. Flag that indicates whether to include default roles, such as snc_internal and snc_external, in the request. For additional information on roles, see Exploring user administration.

Default: false

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

Example

var yesRole = g_user.hasRoles();

Example

var yesRole = g_user.hasRoles(true);

GlideUser - lastName

The current user's last name.

Table 14. Field
Name Type Description
lastName String Current user's last name.

Example

alert('last name = ' + g_user.lastName);

GlideUser - setClientData(String key, String value)

Sets a client value that you can retrieve using getClientData().

See also GlideForm.

Table 15. Parameters
Name Type Description
key String Name of the client data to store as a key.
value Number Value to assign to the key.
Table 16. Returns
Type Description
None

Example

function onSubmit() {
	
	if (!g_user.getClientData('keyName')) {
		var now_GR = new GlideRecord('incident');
		now_GR.addActiveQuery();
		now_GR.setLimit(1);
		now_GR.query(cb);
		return false;
	}
	return true;
}

function cb(now_GR) {
	// <insert glide operation >
	g_user.setClientData('keyName', now_GR.getValue('<number>'));
	g_form.submit();	
}

GlideUser - userName

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

Table 17. Field
Name Type Description
userName String Current user's username.

Example

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

GlideUser - userID

Returns the sys_id of the current user.

Table 18. Field
Name Type Description
userID String Sys_id of the current user.

Example

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