You can set custom fields for specific users while registering or updating user information. For example, you can add fields like address or employee ID.
You may need some basic understanding of Javascript and Rocket.Chat's internal working structure is required to set other custom fields than those in the example below. A more user-friendly interface is planned for the future.
Define custom fields
To set custom fields, go to Manage → Workspace → Settings → Accounts → Registration → Custom Fields. Configure the custom fields using a JSON object containing a dictionary of field settings. Let's look at two examples. The setting provides a code editor with line numbers; click Full Screen to expand the editor while working with larger configurations.
Basic example
In this example, we add two custom fields, team and designation, with the type text. This means that the custom fields can take any text values as input.
{
"team": {
"type": "text"
},
"designation": {
"type": "text"
}
}Custom field keys are case-sensitive. The key you define here (for example,
team) is the exact name you must use everywhere the field is referenced, such as in Custom Fields to Show in User Info or via the API.
Once these custom fields are saved, you can enter the values for the fields while creating a new user or updating an existing user. The following screenshot shows the example:
.png)
Advanced example
Here, role is a custom field consisting of two options (teacher and student) as the possible values. twitter and dept are text fields where you can enter values according to the defined settings.
{
"role": {
"type": "select",
"defaultValue": "student",
"options": ["teacher", "student"],
"required": true,
"modifyRecordField": {
"array": true,
"field": "roles"
}
},
"twitter": {
"type": "text",
"required": true,
"minLength": 2,
"maxLength": 10
},
"dept": {
"type": "text",
"required": false,
"minLength": 12,
"sendToIntegrations": true
}
}Let's look at the properties in detail:
Parameter | Description |
|---|---|
type | Defines the type of the custom field. Currently, there are 2 types: |
defaultValue | Used with a |
options | Used with a |
required | Set whether the field is required for registration. Enter |
minLength | Used with the |
maxLength | Used with the |
modifyRecordField | This property is required when you add a field that already exists in Rocket.Chat.
|
array | Used inside the |
field | Used inside the |
public | Defines the field as visible to other users when viewing the user's profile. Enter |
private | Defines the field as private. Only users with |
sendToIntegrations | Defines the field as shareable with external applications, such as Omnichannel integrations. |
Use tabs for indentation in the JSON object, do not use spaces.
You can also use the API to create and manage custom fields. See the Create User, Update User, and Get Users List endpoints.
Display user’s custom fields
You can configure the list of custom fields displayed on the User Info panel. Go to Manage → Workspace → Settings → Accounts → Custom Fields to Show in User Info.
The value must be a JSON array of objects, where each object's key is the label shown to users and its value is the custom field name defined previously:
[{"label1":"key1"},{"label2":"key2"},...]The label can be the name of the custom field that is displayed for users. The key must be a custom field name defined previously. Considering the previous example, the field can look something like this:
[{"Role":"role"},{"Department":"dept"}]This means that the role and dept custom fields will be displayed on the User Info panel with the labels Role and Department. Note that a field is only shown if it is set to "public": true or if the viewer has permission to view private fields.
Set custom field values
Now that you have configured the custom fields, they will be displayed when creating new users or updating existing ones. Enter the respective values and save the user details.