{"record":{"id":"956b6bf6967ed719","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-custom-field-value","errorCode":"error-invalid-custom-field-value","errorMessage":"error-invalid-custom-field-value","messagePattern":"error-invalid-custom-field-value","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/contacts/validateCustomFields.ts","lineNumber":19,"sourceCode":"import type { AtLeast, ILivechatCustomField } from '@rocket.chat/core-typings';\n\nimport { i18n } from '../../../../app/utils/lib/i18n';\nimport { trim } from '../../../../lib/utils/stringUtils';\n\nexport function validateCustomFields(\n\tallowedCustomFields: AtLeast<ILivechatCustomField, '_id'>[],\n\tcustomFields: Record<string, string | unknown>,\n\t{\n\t\tignoreAdditionalFields = false,\n\t\tignoreValidationErrors = false,\n\t}: { ignoreAdditionalFields?: boolean; ignoreValidationErrors?: boolean } = {},\n): Record<string, string> {\n\tconst validValues: Record<string, string> = {};\n\n\tfor (const cf of allowedCustomFields) {\n\t\tif (!customFields.hasOwnProperty(cf._id)) {\n\t\t\tif (cf.required && !ignoreValidationErrors) {\n\t\t\t\tthrow new Error(i18n.t('error-invalid-custom-field-value', { field: cf.label || cf._id }));\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst cfValue: string = trim(customFields[cf._id]);\n\n\t\tif (!cfValue || typeof cfValue !== 'string') {\n\t\t\tif (cf.required && !ignoreValidationErrors) {\n\t\t\t\tthrow new Error(i18n.t('error-invalid-custom-field-value', { field: cf.label || cf._id }));\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (cf.regexp) {\n\t\t\tconst regex = new RegExp(cf.regexp);\n\t\t\tif (!regex.test(cfValue)) {\n\t\t\t\tif (ignoreValidationErrors) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/contacts/validateCustomFields.ts#L1-L37","documentation":"In validateCustomFields, a custom field marked required=true in the LivechatCustomField collection was entirely absent from the submitted customFields object. The thrown message is the translated 'error-invalid-custom-field-value' string with the field's label (or _id) interpolated. Absence of a required field is treated exactly like an invalid value.","triggerScenarios":"Registering or updating a contact/visitor with a customFields payload that omits one or more fields flagged required in Administration > Omnichannel > Custom Fields (unless ignoreValidationErrors was passed true by the calling code path).","commonSituations":"A new required custom field was added after the client form was built; third-party webhook sends a fixed set of fields; client omits keys with empty values.","solutions":["List required fields (GET /api/v1/livechat/custom-fields and filter required) and include every one in the payload","If the field should be optional, clear 'required' in the custom-field settings","For import/best-effort flows, use a code path that passes ignoreValidationErrors: true to skip missing required fields"],"exampleFix":"// before\nawait registerContact({ token, email, customFields: { company: 'ACME' } }, userId); // 'address' is required\n\n// after\nawait registerContact({ token, email, customFields: { company: 'ACME', address: '1 Main St' } }, userId);","handlingStrategy":"validation","validationCode":"const fields = await LivechatCustomField.find({ scope: 'visitor' }).toArray();\nconst missing = fields.filter((f) => f.required && !(f._id in customFields));\nif (missing.length) throw new Error(`Missing required custom fields: ${missing.map((f) => f._id).join(', ')}`);\nawait registerContact({ ...params, customFields }, userId);","typeGuard":"const hasAllRequired = (payload: Record<string, unknown>, required: string[]): payload is Record<string, string> =>\n  required.every((id) => id in payload);","tryCatchPattern":"try {\n  await registerContact(params, userId);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('error-invalid-custom-field-value')) {\n    // message names the field; add it to the payload or mark it optional in settings\n  }\n  throw err;\n}","preventionTips":["Build forms dynamically from the live custom-fields list so new required fields appear automatically","Fetch required field ids at runtime instead of hardcoding","Keep a workspace-provisioning step that documents which fields are required"],"tags":["omnichannel","livechat","custom-fields","required-field","validation","i18n"],"backgroundTag":"required-field-missing","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}