{"record":{"id":"9ec2190c05ba7268","repo":"RocketChat/Rocket.Chat","slug":"error-business-hour-name-already-in-use","errorCode":null,"errorMessage":"error-business-hour-name-already-in-use","messagePattern":"error-business-hour-name-already-in-use","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/lib/omnichannel/business-hour/Custom.ts","lineNumber":44,"sourceCode":"\n\t\tconst businessHour = await this.BusinessHourRepository.findOneById(id);\n\t\tif (!businessHour) {\n\t\t\treturn null;\n\t\t}\n\n\t\tbusinessHour.departments = await LivechatDepartment.findByBusinessHourId(businessHour._id, {\n\t\t\tprojection: { name: 1 },\n\t\t}).toArray();\n\t\treturn businessHour;\n\t}\n\n\tasync saveBusinessHour(businessHour: ILivechatBusinessHour & IBusinessHoursExtraProperties): Promise<ILivechatBusinessHour> {\n\t\tconst existingBusinessHour = (await this.BusinessHourRepository.findOne(\n\t\t\t{ name: businessHour.name },\n\t\t\t{ projection: { _id: 1 } },\n\t\t)) as ILivechatBusinessHour;\n\t\tif (existingBusinessHour && existingBusinessHour._id !== businessHour._id) {\n\t\t\tthrow new Error('error-business-hour-name-already-in-use');\n\t\t}\n\t\tconst { timezoneName, departmentsToApplyBusinessHour, ...businessHourData } = businessHour;\n\t\tbusinessHourData.timezone = {\n\t\t\tname: timezoneName,\n\t\t\tutc: this.getUTCFromTimezone(timezoneName),\n\t\t};\n\t\tconst businessHourToReturn = { ...businessHourData, departmentsToApplyBusinessHour };\n\t\tdelete businessHourData.departments;\n\n\t\tconst businessHourId = await this.baseSaveBusinessHour(businessHourData);\n\n\t\t// Internal callers (e.g. the DST verifier) re-save business hours without the\n\t\t// departments field; only reconcile department links when it is provided,\n\t\t// otherwise an internal re-save would unlink every department.\n\t\tif (departmentsToApplyBusinessHour !== undefined) {\n\t\t\tconst departments = departmentsToApplyBusinessHour.split(',').filter(Boolean);\n\t\t\tconst currentDepartments = (\n\t\t\t\tawait LivechatDepartment.findByBusinessHourId(businessHourId, {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/lib/omnichannel/business-hour/Custom.ts#L26-L62","documentation":"saveBusinessHour in the Custom (single/timezone) business-hour implementation queries for an existing business hour with the same name. If one exists with a different _id, it throws error-business-hour-name-already-in-use to keep names unique.","triggerScenarios":"Creating a business hour whose name is already taken, or renaming a business hour to another one's name (existingBusinessHour._id !== businessHour._id).","commonSituations":"Admins creating similarly named business hours ('Business Hours' vs 'business hours'); importing a duplicate configuration; copy-then-rename workflows that keep the original name.","solutions":["Choose a distinct name for the business hour","Rename or delete the existing business hour that holds the name first","When duplicating for another timezone, append the timezone to the name"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const existing = await LivechatBusinessHours.findOneByName(businessHour.name);\nif (existing && existing._id !== businessHour._id) {\n\t// name taken: ask for a different name before saving\n}\nawait saveBusinessHour(businessHour);","typeGuard":null,"tryCatchPattern":"try {\n\tawait saveBusinessHour(businessHour);\n} catch (err) {\n\tif (err instanceof Error && err.message === 'error-business-hour-name-already-in-use') {\n\t\t// prompt for a unique name; keep form data intact\n\t} else {\n\t\tthrow err;\n\t}\n}","preventionTips":["Validate business hour names for uniqueness in the form before submit","When cloning hours for another timezone, suffix the name with the timezone","Rename or delete the conflicting hour before reusing its name"],"tags":["omnichannel","business-hour","duplicate","validation"],"backgroundTag":"duplicate-name-conflict","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"}