GlideUser - Scoped

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

Scoped GlideUser - getCompanyID()

Gets the company sys_id of the current user.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
String The company sys_id.
var currentUser = gs.getUser(); 
gs.info(currentUser.getCompanyID());

Output:

Scoped GlideUser - getDisplayName()

Gets the display name of the current user.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String The user's display name.
var currentUser = gs.getUser(); 
gs.info(currentUser.getDisplayName());

Output:

Scoped GlideUser - getID()

Gets the sys_id of the current user.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String The user's sys_id.
var currentUser = gs.getUser(); 
gs.info(currentUser.getID());

Output:

Scoped GlideUser - getName()

Gets the user id, or login name, of the current user.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String The user ID.
var currentUser = gs.getUser(); 
gs.info(currentUser.getName());

Output:

Scoped GlideUser - getPreference(String name)

Gets the specified user preference value for the current user.

Table 9. Parameters
Name Type Description
name String The name of the preference.
Table 10. Returns
Type Description
String The preference value.
var currentUser = gs.getUser(); 
currentUser.savePreference(­'myPref','red'); 
gs.info(currentUser.getPreference(­'myPref'));

Output:

Scoped GlideUser - hasRole(String role)

Determines if the current user has the specified role.

Table 11. Parameters
Name Type Description
role String The role to check.
Table 12. Returns
Type Description
Boolean True if the user has the role.
var currentUser = gs.getUser(); 
gs.info(currentUser.hasRole('admin'));

Output:

Scoped GlideUser - isMemberOf(String group)

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

Table 13. Parameters
Name Type Description
group String The group to check.
Table 14. Returns
Type Description
Boolean True if the user is a member of the group.
var currentUser = gs.getUser(); 
gs.info(currentUser.isMemberOf(­'Capacity Mgmt'));

Output:

Scoped GlideUser - savePreference(String name, String value)

Saves a user preference value to the database.

Table 15. Parameters
Name Type Description
name String The preference to save.
value String The preference value.
Table 16. Returns
Type Description
void
var currentUser = gs.getUser(); 
currentUser.savePreference('myPref','red'); 
gs.info(currentUser.getPreference('myPref'));

Output: