reference1 min readApplication: Platform
user and User
Methods of the server-side user object and the client-side User object, which read the signed-in user's details, roles, groups and properties.
Two globals describe the signed-in user. user, all lower case, is available in server scripts. User, with a capital U, is available in client scripts such as UI events.
Get an instance
Both are ready to use. There is nothing to create.
// Server script
let userId = user.getID();
// Client script
let clientUserId = User.getID();
Server user methods
On the server, user also gives the fields of the user’s record by name: user.Email() reads the Email field.
| Method | Returns | Description | Since |
|---|---|---|---|
getID() |
String | The ID of the user’s record. | 1.11 |
getName() |
String | The user’s full name. | 1.11 |
getUserName() |
String | The user name. | 1.11 |
getFirstName() |
String | The first name. | 1.11 |
getLastName() |
String | The last name. | 1.11 |
getEmail() |
String | The primary email address. | 1.11 |
getTitle() |
String | The job title. | 1.11 |
getDeskPhone() |
String | The desk phone number. | 1.11 |
getMobile() |
String | The mobile number. | 1.11 |
getTimeZone() |
String | The time zone ID from the user’s record. | 1.11 |
getCompanyID() |
String | The ID of the user’s company. | 1.11 |
getRecord() |
TableRecord | The user’s record. | 1.11 |
getDisplayValue() |
String | The display value of the user’s record. displayValue() is the same. |
1.11 |
evaluate(path) |
Any | The value at a dot path from the user’s record, for example "Company.Name". |
1.11 |
locale() |
String | The session’s locale, for example "en_US". |
1.11 |
getRoles() |
Array | The names of the user’s roles. getRoleNames() is the same. |
1.11 |
getRoleIDs() |
Array | The IDs of the user’s roles. | 1.11 |
hasRole(role) |
Boolean | True when the user holds the role, by name or ID. | 1.11 |
hasAnyRole(roles) |
Boolean | True when the user holds at least one of the roles. Pass names as separate arguments or as one array. | 1.11 |
hasEffectiveRole(role) |
Boolean | True when the session’s effective user holds the role, by name or ID. | 1.11 |
isAdministrator() |
Boolean | True when the user holds administrator. |
1.11 |
isSystem() |
Boolean | True when the user holds system. |
1.11 |
getGroupNames() |
Array | The names of the user’s groups. | 1.11 |
getGroupIDs() |
Array | The IDs of the user’s groups. | 1.11 |
isMemberOfGroup(group) |
Boolean | True when the user is in the group, by name or ID. | 1.11 |
getProfileProperty(key) |
String | A value from the user’s profile, or null. | 1.11 |
getProfileProperty(key, default) |
String | A value from the user’s profile, or default. |
1.11 |
setProfileProperty(key, value) |
Nothing | Saves a value in the user’s profile. | 1.11 |
isAuthenticated() |
Boolean | True when a user is signed in. | 1.11 |
isHardCodedUser() |
Boolean | True for a built-in user, such as the system user, or when nobody is signed in. | 1.11 |
isImpersonated() |
Boolean | True when the session is impersonating the user. | 1.11 |
getCurrentTenantID() |
String | The ID the tenancy filter uses now. With realm hierarchy tenancy, it is the realm chosen in the realm selector. Null without tenancy. | 1.11 |
getPrimaryTenantID() |
String | The ID of the user’s own tenancy filter. With realm hierarchy tenancy, it is the realm on the user’s record. Null without tenancy. | 1.11 |
Client User methods
| Method | Returns | Description | Since |
|---|---|---|---|
getID() |
String | The ID of the user’s record. | 1.11 |
getUserName() |
String | The user name. | 1.11 |
getFirstName() |
String | The first name. | 1.11 |
getLastName() |
String | The last name. | 1.11 |
getEmail() |
String | The primary email address. | 1.11 |
getTimeZone() |
String | The time zone ID. | 1.11 |
getLanguage() |
String | The user’s language. | 1.11 |
getRoles() |
Array | The names of the user’s roles. | 1.11 |
hasRole(role) |
Boolean | True when the user holds the role. | 1.11 |
isAuthenticated() |
Boolean | True when a user is signed in. | 1.11 |
getProperty(key, default) |
String | An application property marked Client side accessible, or default when it does not exist. |
1.11 |
getBooleanProperty(key, default) |
Boolean | The same, as a boolean. | 1.11 |
getIntegerProperty(key, default) |
Number | The same, as a whole number. | 1.11 |
getUserProfileProperty(key, default) |
String | A value from the user’s profile, or default. |
1.11 |
getBooleanUserProfileProperty(key, default) |
Boolean | The same, as a boolean. | 1.11 |
getIntegerUserProfileProperty(key, default) |
Number | The same, as a whole number. | 1.11 |
setUserProfileProperty(key, value) |
Nothing | Saves a value in the user’s profile. | 1.11 |
Examples
Check roles on the server
Servicely Script
[
user.hasRole("administrator"),
user.hasAnyRole("itsm_manager", "knowledge_manager"),
user.isMemberOfGroup("<group name>")
];
Response
[false, true, true]
Read a property in a client script
if (User.getBooleanProperty("system.multilingual", false)) {
current.<FieldName>.visible(true);
}