{"record":{"id":"8551baba80e3af4e","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-custom-field-value-8551ba","errorCode":"error-invalid-custom-field-value","errorMessage":"error-invalid-custom-field-value","messagePattern":"error-invalid-custom-field-value","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/rooms.ts","lineNumber":177,"sourceCode":"\t\tlivechatData?: { [k: string]: string };\n\t},\n\tuserId?: string,\n) {\n\tlivechatLogger.debug({ msg: 'Saving room information', roomId: roomData._id });\n\tconst { livechatData = {} } = roomData;\n\tconst customFields: Record<string, string> = {};\n\n\tif ((!userId || (await hasPermissionAsync(userId, 'edit-livechat-room-customfields'))) && Object.keys(livechatData).length) {\n\t\tconst fields = LivechatCustomField.findByScope('room');\n\t\tfor await (const field of fields) {\n\t\t\tif (!livechatData.hasOwnProperty(field._id)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst value = trim(livechatData[field._id]);\n\t\t\tif (value !== '' && field.regexp !== undefined && field.regexp !== '') {\n\t\t\t\tconst regexp = new RegExp(field.regexp);\n\t\t\t\tif (!regexp.test(value)) {\n\t\t\t\t\tthrow new Meteor.Error(i18n.t('error-invalid-custom-field-value', { field: field.label }));\n\t\t\t\t}\n\t\t\t}\n\t\t\tcustomFields[field._id] = value;\n\t\t}\n\t\troomData.livechatData = customFields;\n\t\tlivechatLogger.debug({\n\t\t\tmsg: 'About to update custom fields on room',\n\t\t\troomId: roomData._id,\n\t\t\tcustomFieldCount: Object.keys(customFields).length,\n\t\t});\n\t}\n\n\tawait LivechatRooms.saveRoomById(roomData);\n\n\tsetImmediate(() => {\n\t\tvoid Apps.self?.triggerEvent(AppEvents.IPostLivechatRoomSaved, roomData._id);\n\t});\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/rooms.ts#L159-L195","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before - regexp on the field is ^\\d+$\nconst roomInfo = { title: 'Support', livechatData: { orderId: 'AB-12' } };\n\n// after\nconst roomInfo = { title: 'Support', livechatData: { orderId: '12' } };","handlingStrategy":"validation","validationCode":"for (const [key, rawValue] of Object.entries(livechatData)) {\n\tconst field = LivechatCustomField.findOneById(key);\n\tconst value = String(rawValue).trim();\n\tif (field?.regexp && value !== '' && !new RegExp(field.regexp).test(value)) {\n\t\tthrow new Error(`invalid value for custom field '${field.label}'`);\n\t}\n}","typeGuard":"const isValidCustomFieldValue = (field: { regexp?: string }, value: string): boolean =>\n\tvalue.trim() === '' || !field.regexp || new RegExp(field.regexp).test(value.trim());","tryCatchPattern":"try {\n\tawait createRoom({ visitor, roomInfo });\n} catch (err) {\n\tif (err instanceof Meteor.Error && String(err.error).includes('error-invalid-custom-field-value')) {\n\t\t// highlight the offending field in the form; keep the user's other input\n\t\treturn;\n\t}\n\tthrow err;\n}","preventionTips":["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."],"tags":["omnichannel","livechat","custom-fields","validation","rooms"],"backgroundTag":"custom-field-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}