RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-custom-field-value
error-invalid-custom-field-value
Error message
error-invalid-custom-field-value
What it means
While processing room custom fields, each provided livechatData entry that has a configured regexp and a non-empty trimmed value is tested with new RegExp(field.regexp). A failing value raises Meteor.Error with i18n key 'error-invalid-custom-field-value' and the field label interpolated. Empty strings skip validation entirely.
Source
Thrown at apps/meteor/server/lib/omnichannel/rooms.ts:177
livechatData?: { [k: string]: string };
},
userId?: string,
) {
livechatLogger.debug({ msg: 'Saving room information', roomId: roomData._id });
const { livechatData = {} } = roomData;
const customFields: Record<string, string> = {};
if ((!userId || (await hasPermissionAsync(userId, 'edit-livechat-room-customfields'))) && Object.keys(livechatData).length) {
const fields = LivechatCustomField.findByScope('room');
for await (const field of fields) {
if (!livechatData.hasOwnProperty(field._id)) {
continue;
}
const value = trim(livechatData[field._id]);
if (value !== '' && field.regexp !== undefined && field.regexp !== '') {
const regexp = new RegExp(field.regexp);
if (!regexp.test(value)) {
throw new Meteor.Error(i18n.t('error-invalid-custom-field-value', { field: field.label }));
}
}
customFields[field._id] = value;
}
roomData.livechatData = customFields;
livechatLogger.debug({
msg: 'About to update custom fields on room',
roomId: roomData._id,
customFieldCount: Object.keys(customFields).length,
});
}
await LivechatRooms.saveRoomById(roomData);
setImmediate(() => {
void Apps.self?.triggerEvent(AppEvents.IPostLivechatRoomSaved, roomData._id);
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Send a value matching the field's configured regexp (check Administration > Omnichannel > Custom Fields).
- Send '' (or omit the key) for optional fields — empty values skip the regexp check.
- If the integration legitimately sends other formats, update the regexp on the custom field definition.
Example fix
// before - regexp on the field is ^\d+$
const roomInfo = { title: 'Support', livechatData: { orderId: 'AB-12' } };
// after
const roomInfo = { title: 'Support', livechatData: { orderId: '12' } }; Defensive patterns
Strategy: validation
Validate before calling
for (const [key, rawValue] of Object.entries(livechatData)) {
const field = LivechatCustomField.findOneById(key);
const value = String(rawValue).trim();
if (field?.regexp && value !== '' && !new RegExp(field.regexp).test(value)) {
throw new Error(`invalid value for custom field '${field.label}'`);
}
} Type guard
const isValidCustomFieldValue = (field: { regexp?: string }, value: string): boolean =>
value.trim() === '' || !field.regexp || new RegExp(field.regexp).test(value.trim()); Try / catch
try {
await createRoom({ visitor, roomInfo });
} catch (err) {
if (err instanceof Meteor.Error && String(err.error).includes('error-invalid-custom-field-value')) {
// highlight the offending field in the form; keep the user's other input
return;
}
throw err;
} Prevention
- Load custom field definitions (including regexp) and validate client-side before submission.
- Send '' or omit optional fields instead of placeholder values like 'N/A'.
- When regexps change on the server, version and re-test every integration that sends livechatData.
When it happens
Trigger: Creating/updating an omnichannel room with livechatData whose value fails the custom field's regexp — e.g., orderId: 'abc' against ^\d+$ — from a caller without edit-livechat-room-customfields (typically the visitor flow, since that permission check gates the branch).
Common situations: A custom field's regexp was tightened after integrations shipped; the widget sends untrimmed or wrongly-typed values; developers confuse the field's label with its _id when configuring.
Related errors
- error-invalid-custom-field-value
- error-custom-field-not-allowed
- Missing required custom fields: ${errors.join(', ')}
- invalid-custom-field
- error-invalid-custom-field-value
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/8551baba80e3af4e.
Report an issue: GitHub.