{"record":{"id":"cd01daaed26754d8","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-priority-cd01da","errorCode":"error-invalid-priority","errorMessage":"Invalid priority","messagePattern":"Invalid priority","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts","lineNumber":31,"sourceCode":"\t\t}\n\t\tlet sla: IOmnichannelServiceLevelAgreements | null = null;\n\t\tlet priority: ILivechatPriority | null = null;\n\t\tif (slaSearchTerm) {\n\t\t\tsla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(slaSearchTerm, {\n\t\t\t\tprojection: { dueTimeInMinutes: 1 },\n\t\t\t});\n\t\t\tif (!sla) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-sla', 'Invalid sla', {\n\t\t\t\t\tfunction: 'livechat.beforeInquiry',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (prioritySearchTerm) {\n\t\t\tpriority = await LivechatPriority.findOneByIdOrName(prioritySearchTerm, {\n\t\t\t\tprojection: { _id: 1, sortItem: 1 },\n\t\t\t});\n\t\t\tif (!priority) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-priority', 'Invalid priority', {\n\t\t\t\t\tfunction: 'livechat.beforeInquiry',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst ts = new Date();\n\t\tconst changes: Partial<ILivechatInquiryRecord> = {\n\t\t\tts,\n\t\t};\n\t\tif (sla) {\n\t\t\tchanges.slaId = sla._id;\n\t\t\tchanges.estimatedWaitingTimeQueue = sla.dueTimeInMinutes;\n\t\t}\n\t\tif (priority) {\n\t\t\tchanges.priorityId = priority._id;\n\t\t\tchanges.priorityWeight = priority.sortItem;\n\t\t}\n\t\treturn { ...props, ...changes };\n\t},","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts#L13-L49","documentation":"Thrown by the 'livechat.beforeNewInquiry' hook when extraData.priority is set but LivechatPriority.findOneByIdOrName cannot find a matching priority record by id or name. The priority drives queue sortItem ordering on the inquiry, so an unresolvable reference aborts inquiry creation rather than silently defaulting.","triggerScenarios":"Creating a livechat inquiry with a priority id/name that was deleted, renamed, or typo'd; integrations replaying cached priority identifiers after an environment refresh.","commonSituations":"Priorities re-seeded between environments (dev -> prod) with new ids; clients hard-coding priority names like 'highest' that were localized or renamed.","solutions":["List current priorities (Administration > Omnichannel > Priorities or the priorities API) and send a valid _id or exact name","Recreate the missing priority or update the calling integration","Drop the priority field if the inquiry should use the default queue ordering"],"exampleFix":"// before: assuming the priority exists\nawait createInquiry({ ...data, priority: 'high-prio' });\n\n// after: validate the reference beforehand\nconst priority = await LivechatPriority.findOneByIdOrName('high-prio', {\n  projection: { _id: 1, sortItem: 1 },\n});\nif (!priority) throw new Error('Unknown priority: high-prio');\nawait createInquiry({ ...data, priority: 'high-prio' });","handlingStrategy":"validation","validationCode":"const priorityExists = async (term: string): Promise<boolean> =>\n  Boolean(await LivechatPriority.findOneByIdOrName(term, { projection: { _id: 1 } }));","typeGuard":null,"tryCatchPattern":"try {\n  await createInquiry({ ...data, priority: term });\n} catch (err: any) {\n  if (err?.error === 'error-invalid-priority') {\n    // fetch current priorities and correct the reference\n  }\n  throw err;\n}","preventionTips":["Seed environments with the same priority ids/names used by clients","Validate priority names on the client against the priorities API before submit","Avoid localized display names as API identifiers"],"tags":["omnichannel","livechat","priority","entity-not-found"],"backgroundTag":"priority-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}