{"record":{"id":"b751c1644c4de3f7","repo":"RocketChat/Rocket.Chat","slug":"error-forwarding-chat-same-department","errorCode":"error-forwarding-chat-same-department","errorMessage":"error-forwarding-chat-same-department","messagePattern":"error-forwarding-chat-same-department","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/omnichannel/Helper.ts","lineNumber":654,"sourceCode":"\tconst inquiry = await LivechatInquiry.findOneByRoomId(rid, {});\n\tif (!inquiry) {\n\t\tlogger.debug({\n\t\t\tmsg: 'Cannot forward room. No inquiries found',\n\t\t\troomId: room._id,\n\t\t});\n\t\tthrow new Error('error-transferring-inquiry');\n\t}\n\n\tconst { departmentId } = transferData;\n\tif (!departmentId) {\n\t\tlogger.debug({\n\t\t\tmsg: 'Cannot forward room. No departmentId provided',\n\t\t\troomId: room._id,\n\t\t});\n\t\tthrow new Error('error-transferring-inquiry-no-department');\n\t}\n\tif (oldDepartmentId === departmentId) {\n\t\tthrow new Error('error-forwarding-chat-same-department');\n\t}\n\n\tconst { userId: agentId, clientAction } = transferData;\n\tif (agentId) {\n\t\tlogger.debug({\n\t\t\tmsg: 'Forwarding room to department and user',\n\t\t\troomId: room._id,\n\t\t\tdepartmentId,\n\t\t\tagentId,\n\t\t});\n\t\tconst user = await Users.findOneOnlineAgentById(\n\t\t\tagentId,\n\t\t\tsettings.get<boolean>('Livechat_enabled_when_agent_idle'),\n\t\t\tsettings.get<boolean>('Livechat_accept_chats_with_no_agents'),\n\t\t\t{},\n\t\t);\n\t\tif (!user) {\n\t\t\tthrow new Error('error-user-is-offline');","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/Helper.ts#L636-L672","documentation":"forwardRoomToDepartment rejects transfers whose target departmentId equals the room's current oldDepartmentId - forwarding a chat to the department that already owns it is a no-op. It fires after the presence check, so a non-empty but identical ID triggers it.","triggerScenarios":"Transfer dialog submitted with the current department selected; automation copying room.departmentId into transferData; supervisor re-forwarding to the same department to 'reset' the chat.","commonSituations":"Default department selection in the UI being the current one; departments with only one viable option; scripts that echo state back into the request.","solutions":["Pick a different department as the forward target","UI: exclude the room's current department from the target list or warn before submit","To force re-queueing within the same department, use the queue/return flow instead of forward"],"exampleFix":"// before\nawait forwardRoomToDepartment(room, { departmentId: room.departmentId }, guest);\n\n// after\nif (room.departmentId === targetDeptId) {\n  throw new Error('error-forwarding-chat-same-department');\n}\nawait forwardRoomToDepartment(room, { departmentId: targetDeptId }, guest);","handlingStrategy":"validation","validationCode":"if (room.departmentId === transferData.departmentId) {\n  // same-department forward is a no-op; block or warn in the UI\n  throw new Error('error-forwarding-chat-same-department');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await forwardRoomToDepartment(room, transferData, guest);\n} catch (err) {\n  if (err instanceof Error && err.message === 'error-forwarding-chat-same-department') {\n    // benign: prompt for a different department\n  } else throw err;\n}","preventionTips":["Exclude the room's current department from target lists","Use the queue/return flow to re-queue inside the same department"],"tags":["omnichannel","livechat","transfer","department","duplicate","rocket-chat"],"backgroundTag":"duplicate-operation","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}