{"record":{"id":"6c24f6f61ab003ee","repo":"RocketChat/Rocket.Chat","slug":"error-transferring-inquiry-no-department","errorCode":"error-transferring-inquiry-no-department","errorMessage":"error-transferring-inquiry-no-department","messagePattern":"error-transferring-inquiry-no-department","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/Helper.ts","lineNumber":651,"sourceCode":"\tconst { _id: rid, servedBy: oldServedBy, departmentId: oldDepartmentId } = room;\n\tlet agent = null;\n\n\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{},","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/Helper.ts#L633-L669","documentation":"Thrown by the department-forward path when transferData.departmentId is falsy - the required target department was not supplied. It fires before any database lookup, making it pure argument validation.","triggerScenarios":"REST livechat/room.forward payload missing departmentId; the frontend sends userId only but the call routes into the department-forward branch; department select cleared so an empty string is submitted.","commonSituations":"Form validation gaps; API consumers assuming departmentId is optional; department deleted client-side before submit.","solutions":["Provide a valid departmentId in transferData","Validate the payload against the endpoint schema before submitting","If no department is intended, use the agent forward path with userId instead"],"exampleFix":"// before\nawait forwardRoomToDepartment(room, { clientAction: 'forward' }, guest);\n\n// after\nconst { departmentId } = transferData;\nif (!departmentId) throw new Error('error-transferring-inquiry-no-department');\nawait forwardRoomToDepartment(room, { ...transferData, departmentId }, guest);","handlingStrategy":"validation","validationCode":"const isNonEmptyId = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0;\nif (!isNonEmptyId(transferData.departmentId)) {\n  throw new Error('error-transferring-inquiry-no-department');\n}\nawait forwardRoomToDepartment(room, transferData, guest);","typeGuard":"const isNonEmptyId = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  await forwardRoomToDepartment(room, transferData, guest);\n} catch (err) {\n  if (err instanceof Error && err.message === 'error-transferring-inquiry-no-department') {\n    // payload lost departmentId - require it in the form and resubmit\n  } else throw err;\n}","preventionTips":["Make departmentId required in transfer forms routed to the department path","Validate forward payloads against the endpoint schema before submit"],"tags":["omnichannel","livechat","transfer","missing-parameter","rocket-chat"],"backgroundTag":"missing-required-parameter","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}