{"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/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/hooks/omnichannel/beforeForwardRoomToDepartment.ts#L14-L37","documentation":"Thrown by the 'livechat.beforeForwardRoomToDepartment' hook when the department the room currently belongs to declares a non-empty departmentsAllowedToForward list and the target department is not in it. It enforces per-department forwarding ACLs: once a list exists, only listed departments may receive that room.","triggerScenarios":"Forwarding/transferring an omnichannel room to department B while the room's current department A has departmentsAllowedToForward = [C, D]; REST API livechat.transfer or the UI transfer widget targeting a non-allowed department.","commonSituations":"Department-level forwarding restrictions configured after workflows were built; new departments created but never added to allowed lists; automation scripts transferring to a hard-coded departmentId that is no longer allowed.","solutions":["Add the target department to the current department's 'Forwarding allowed departments' (departmentsAllowedToForward) in Administration > Omnichannel Departments","Or forward to one of the departments already present in the allowed list","If restrictions are legacy, clear the departmentsAllowedToForward list (empty means unrestricted) on the current department"],"exampleFix":"// before: transferring straight into a restricted target\nawait transferRoom(rid, { departmentId: targetDeptId });\n\n// after: check the current department's ACL the same way the hook does\nconst current = await LivechatDepartment.findOneById(room.departmentId, {\n  projection: { departmentsAllowedToForward: 1 },\n});\nconst allowed = current?.departmentsAllowedToForward ?? [];\nif (allowed.length > 0 && !allowed.includes(targetDeptId)) {\n  throw new Error('Target department not allowed for forwarding');\n}\nawait transferRoom(rid, { departmentId: targetDeptId });","handlingStrategy":"validation","validationCode":"const isForwardAllowed = (current: { departmentsAllowedToForward?: string[] }, targetId: string): boolean =>\n  !current.departmentsAllowedToForward?.length || current.departmentsAllowedToForward.includes(targetId);","typeGuard":null,"tryCatchPattern":"try {\n  await transferRoom(rid, { departmentId: target });\n} catch (err: any) {\n  if (err?.error === 'error-forwarding-department-target-not-allowed') {\n    // pick an allowed target or update the department's allow list\n  }\n  throw err;\n}","preventionTips":["Keep transfer UIs filtered to the current department's allowed-forward list","When creating new departments, update existing allow lists that must reach them","Treat a non-empty departmentsAllowedToForward as a strict ACL in automations"],"tags":["omnichannel","livechat","departments","transfer-restrictions"],"backgroundTag":"department-transfer-restricted","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"}