{"record":{"id":"0aeb240d4b331e1a","repo":"RocketChat/Rocket.Chat","slug":"error-forwarding-department-target-not-allowed","errorCode":"error-forwarding-department-target-not-allowed","errorMessage":"The forwarding to the target department is not allowed.","messagePattern":"The forwarding to the target department is not allowed\\.","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/beforeForwardRoomToDepartment.ts","lineNumber":32,"sourceCode":"\t\tconst { departmentId } = room;\n\t\tif (!departmentId) {\n\t\t\treturn options;\n\t\t}\n\t\tconst { department: departmentToTransfer } = transferData;\n\t\tconst currentDepartment = await LivechatDepartment.findOneById<Pick<ILivechatDepartment, 'departmentsAllowedToForward'>>(departmentId, {\n\t\t\tprojection: { departmentsAllowedToForward: 1 },\n\t\t});\n\t\tif (!currentDepartment) {\n\t\t\treturn options;\n\t\t}\n\t\tconst { departmentsAllowedToForward } = currentDepartment;\n\t\tconst isAllowedToTransfer =\n\t\t\t!departmentsAllowedToForward?.length ||\n\t\t\t(Array.isArray(departmentsAllowedToForward) && departmentsAllowedToForward.includes(departmentToTransfer._id));\n\t\tif (isAllowedToTransfer) {\n\t\t\treturn options;\n\t\t}\n\t\tthrow new Meteor.Error('error-forwarding-department-target-not-allowed', 'The forwarding to the target department is not allowed.');\n\t},\n\tcallbacks.priority.HIGH,\n\t'livechat-before-forward-room-to-department',\n);\n","sourceCodeStart":14,"sourceCodeEnd":37,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/omnichannel/beforeForwardRoomToDepartment.ts#L14-L37","documentation":"Thrown by the `beforeForwardRoomToDepartment` omnichannel hook (HIGH priority) when the current department has a non-empty `departmentsAllowedToForward` list that does NOT include the target department's `_id`. It enforces per-department forwarding allowlists for livechat transfers. It is a `Meteor.Error` with code `error-forwarding-department-target-not-allowed`.","triggerScenarios":"Forwarding/transferring a livechat room to a department whose `_id` is not in the source department's `departmentsAllowedToForward` array (and that array is non-empty). If the source department is not found, the hook allows the forward.","commonSituations":"Admin configured a restrictive forwarding allowlist on a department and an agent tries to transfer to a disallowed department; department was renamed/recreated (new `_id`) but the allowlist still references the old id; misconfigured allowlist during department setup.","solutions":["Add the target department's `_id` to the source department's `departmentsAllowedToForward` list.","Transfer to a department that is already in the allowed list.","Clear/relax the `departmentsAllowedToForward` list if forwarding to any department should be permitted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"async function canForwardTo(sourceDeptId: string, targetDeptId: string): Promise<boolean> {\n\tconst dept = await LivechatDepartmentRaw.findOneById(sourceDeptId, { projection: { departmentsAllowedToForward: 1 } });\n\tconst allowed = dept?.departmentsAllowedToForward;\n\treturn !allowed?.length || (Array.isArray(allowed) && allowed.includes(targetDeptId));\n}","typeGuard":"function isForwardingDepartmentTargetNotAllowedError(e: unknown): boolean {\n\treturn e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-forwarding-department-target-not-allowed';\n}","tryCatchPattern":"try {\n\tawait callbacks.run('livechat.beforeForwardRoomToDepartment', options);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-forwarding-department-target-not-allowed') {\n\t\t// add target dept to allowlist or pick an allowed dept\n\t}\n\tthrow e;\n}","preventionTips":["Check the source department's `departmentsAllowedToForward` before offering transfer targets.","Keep allowlists in sync when departments are recreated (new `_id`).","Surface only allowed departments in the transfer UI."],"tags":["omnichannel","livechat","departments","validation","ee","meteor-error"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}