{"record":{"id":"c6aafe4331eadb17","repo":"RocketChat/Rocket.Chat","slug":"error-archived-department-cant-be-enabled","errorCode":"error-archived-department-cant-be-enabled","errorMessage":"Archived departments cant be enabled","messagePattern":"Archived departments cant be enabled","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/departmentsLib.ts","lineNumber":58,"sourceCode":"\t\t: null;\n\n\tif (departmentUnit && !departmentUnit._id && department && department.parentId) {\n\t\tconst isLastDepartmentInUnit = (await LivechatDepartment.countDepartmentsInUnit(department.parentId)) === 1;\n\t\tif (isLastDepartmentInUnit) {\n\t\t\tthrow new Meteor.Error('error-unit-cant-be-empty', \"The last department in a unit can't be removed\", {\n\t\t\t\tmethod: 'livechat:saveDepartment',\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!department && !(await isDepartmentCreationAvailable())) {\n\t\tthrow new Meteor.Error('error-max-departments-number-reached', 'Maximum number of departments reached', {\n\t\t\tmethod: 'livechat:saveDepartment',\n\t\t});\n\t}\n\n\tif (department?.archived && departmentData.enabled) {\n\t\tthrow new Meteor.Error('error-archived-department-cant-be-enabled', 'Archived departments cant be enabled', {\n\t\t\tmethod: 'livechat:saveDepartment',\n\t\t});\n\t}\n\n\t// TODO: Use AJV or Zod for validation (or the lib we are using rn)\n\tconst defaultValidations: Record<string, Match.Matcher<any> | BooleanConstructor | StringConstructor> = {\n\t\tenabled: Boolean,\n\t\tname: String,\n\t\tdescription: Match.Optional(String),\n\t\tshowOnRegistration: Boolean,\n\t\temail: String,\n\t\tshowOnOfflineForm: Boolean,\n\t\trequestTagBeforeClosingChat: Match.Optional(Boolean),\n\t\tchatClosingTags: Match.Optional([String]),\n\t\tfallbackForwardDepartment: Match.Optional(String),\n\t\tdepartmentsAllowedToForward: Match.Optional([String]),\n\t\tallowReceiveForwardOffline: Match.Optional(Boolean),\n\t};","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/departmentsLib.ts#L40-L76","documentation":"Thrown by `livechat:saveDepartment` when the department record being updated has `archived: true` but the incoming `departmentData.enabled` is truthy. Archived departments are frozen; Rocket.Chat refuses to flip `enabled` on them in the same save, forcing an explicit unarchive step first.","triggerScenarios":"Updating a previously archived department (one whose document has `archived: true`) through `livechat:saveDepartment` with `enabled: true` in the payload — e.g. reactivating an old department straight from an 'edit department' form that always sends the enabled checkbox.","commonSituations":"Admin archives a department for decommissioning, later tries to bring it back by just toggling 'Enabled' in the edit screen; automation scripts that upsert departments with a full payload including enabled:true; stale UI state that does not surface the archived flag.","solutions":["Unarchive first via `unarchiveDepartment(_id)` (the lib exported at departmentsLib.ts:165), then save with `enabled: true`","If the department should stay archived, do not send `enabled: true` in the update payload","If the intent is a brand-new active department, create a new one instead of reviving the archived record (mind error 900's quota)"],"exampleFix":"// before\nawait saveDepartment(depId, { ...deptData, enabled: true }); // dep is archived\n\n// after\nif (department.archived) {\n  await unarchiveDepartment(depId);\n}\nawait saveDepartment(depId, { ...deptData, enabled: true });","handlingStrategy":"validation","validationCode":"const dep = await LivechatDepartment.findOneById(_id, { projection: { archived: 1 } });\nif (dep?.archived && deptData.enabled) {\n  await unarchiveDepartment(_id); // unarchive first, then enable\n}\nawait saveDepartment(_id, deptData);","typeGuard":"const isArchivedDepartment = (d: { archived?: boolean } | null): d is { archived: true } =>\n  d?.archived === true;","tryCatchPattern":"try {\n  await saveDepartment(_id, deptData);\n} catch (e) {\n  if (isMeteorError(e, 'error-archived-department-cant-be-enabled')) {\n    await unarchiveDepartment(_id);\n    await saveDepartment(_id, deptData);\n  }\n}","preventionTips":["Show an 'Archived' badge in edit forms and block the enabled toggle until unarchived","Make unarchive an explicit, separate user action","Never blindly upsert full department payloads that include enabled:true"],"tags":["omnichannel","departments","archived","state-transition","livechat"],"backgroundTag":"invalid-state-transition","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}