{"record":{"id":"35e5c73293cdf2f2","repo":"RocketChat/Rocket.Chat","slug":"default-business-hour-not-found","errorCode":null,"errorMessage":"Default business hour not found","messagePattern":"Default business hour not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/lib/omnichannel/business-hour/Multiple.ts","lineNumber":190,"sourceCode":"\t\t}\n\n\t\t// Get business hour\n\t\tlet businessHour = await this.BusinessHourRepository.findOneById(department.businessHourId);\n\t\tif (!businessHour) {\n\t\t\tbhLogger.error({\n\t\t\t\tmsg: 'onDepartmentDisabled: business hour not found',\n\t\t\t\tbusinessHourId: department.businessHourId,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// Unlink business hour from department\n\t\tawait LivechatDepartment.removeBusinessHourFromDepartmentsByIdsAndBusinessHourId([department._id], businessHour._id);\n\n\t\t// cleanup user's cache for default business hour and this business hour\n\t\tconst defaultBH = await this.BusinessHourRepository.findOneDefaultBusinessHour();\n\t\tif (!defaultBH) {\n\t\t\tthrow new Error('Default business hour not found');\n\t\t}\n\t\tawait this.UsersRepository.closeAgentsBusinessHoursByBusinessHourIds([businessHour._id, defaultBH._id]);\n\n\t\t// If i'm the only one, disable the business hour\n\t\tconst imTheOnlyOne = !(await LivechatDepartment.countByBusinessHourIdExcludingDepartmentId(businessHour._id, department._id));\n\t\tif (imTheOnlyOne) {\n\t\t\tbhLogger.warn({\n\t\t\t\tmsg: 'onDepartmentDisabled: department is the only one on business hour, disabling it',\n\t\t\t\tdepartmentId: department._id,\n\t\t\t\tbusinessHourId: businessHour._id,\n\t\t\t});\n\t\t\tawait this.BusinessHourRepository.disableBusinessHour(businessHour._id);\n\n\t\t\tbusinessHour = await this.BusinessHourRepository.findOneById(department.businessHourId);\n\t\t\tif (!businessHour) {\n\t\t\t\tthrow new Error(`Business hour ${department.businessHourId} not found`);\n\t\t\t}\n\t\t}","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/lib/omnichannel/business-hour/Multiple.ts#L172-L208","documentation":"During onDepartmentDisabled, after unlinking a department from its business hour, the code fetches the workspace's default business hour to close agents' caches for both hours. If findOneDefaultBusinessHour() returns null (no default business-hour record), it throws 'Default business hour not found'.","triggerScenarios":"Disabling a department that references a business hour while the instance has no default business-hour document in the database.","commonSituations":"Fresh or migrated installation where the default BH record was never created; default business hour removed manually from the DB; legacy data missing the default record.","solutions":["Re-create/restore the default business hour record (re-enable business hours in settings so defaults are seeded)","Check the LivechatBusinessHours collection for the document with defaultValue/activeDefault flags","If disabling business hours entirely is intended, disable the feature before removing department links"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const defaultBH = await BusinessHourRepository.findOneDefaultBusinessHour();\nif (!defaultBH) {\n\t// re-seed the default business hour before disabling departments\n}\nawait onDepartmentDisabled(department);","typeGuard":null,"tryCatchPattern":"try {\n\tawait onDepartmentDisabled(department);\n} catch (err) {\n\tif (err instanceof Error && err.message === 'Default business hour not found') {\n\t\t// data integrity issue: create/restore the default BH record, then retry\n\t} else {\n\t\tthrow err;\n\t}\n}","preventionTips":["Never manually delete the default business-hour document","Run migrations so the default business hour exists on upgraded instances","Include a default-BH existence check in workspace health checks"],"tags":["omnichannel","business-hour","department","data-integrity"],"backgroundTag":"missing-default-record","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}