{"record":{"id":"adbb1cf73457808d","repo":"actualbudget/actual","slug":"a-date-condition-is-required-to-create-a-schedule","errorCode":null,"errorMessage":"A date condition is required to create a schedule","messagePattern":"A date condition is required to create a schedule","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/loot-core/src/server/schedules/app.ts","lineNumber":333,"sourceCode":"  id: string;\n  targetId: string | null;\n}) {\n  await db.moveSchedule(id, targetId);\n  return {};\n}\n\nexport async function createSchedule({\n  schedule = null,\n  conditions = [],\n}: {\n  schedule?: Partial<ScheduleEntity> | null;\n  conditions?: RuleConditionEntity[];\n} = {}): Promise<ScheduleEntity['id']> {\n  const scheduleId = schedule?.id || uuidv4();\n\n  const { date: dateCond } = extractScheduleConds(conditions);\n  if (dateCond == null) {\n    throw new Error('A date condition is required to create a schedule');\n  }\n  if (dateCond.value == null) {\n    throw new Error('Date is required');\n  }\n\n  const nextDate = getNextDate(dateCond);\n  const nextDateRepr = nextDate ? toDateRepr(nextDate) : null;\n  const scheduleFields = schedule && {\n    ...schedule,\n    name: normalizeScheduleName(schedule.name),\n  };\n  if (scheduleFields) {\n    if (scheduleFields.name) {\n      if (await checkIfScheduleExists(scheduleFields.name, scheduleId)) {\n        throw new Error('Cannot create schedules with the same name');\n      }\n    }\n  }","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/loot-core/src/server/schedules/app.ts#L315-L351","documentation":"`createSchedule` requires at least one date condition among the passed rule conditions (`extractScheduleConds(conditions).date`). Schedules exist to run a rule on a recurring date, so a schedule without a date condition is invalid and rejected.","triggerScenarios":"Calling `createSchedule({ conditions: [...] })` where the conditions array contains only non-date conditions (e.g. only a payee or amount condition), or `conditions` is an empty array.","commonSituations":"API integrations building schedules with only account/payee matching conditions; forgetting that the recurring date itself must be expressed as a `date` condition with an isapprox/recurring value.","solutions":["Add a `date` condition to the conditions array (op `isapprox` with a date or recurring descriptor)","Verify condition `field` is exactly 'date' (extractScheduleConds matches on field name)","Create the schedule via the UI to get a well-formed conditions payload"],"exampleFix":"// before\nawait createSchedule({ conditions: [{ field: 'payee', op: 'is', value: 'landlord' }] });\n// after\nawait createSchedule({\n  conditions: [\n    { field: 'date', op: 'isapprox', value: { frequency: 'monthly', start: '2026-02-01' } },\n    { field: 'payee', op: 'is', value: 'landlord' },\n  ],\n});","handlingStrategy":"validation","validationCode":"function hasDateCondition(conditions = []) {\n  return conditions.some(c => c.field === 'date' && c.value != null);\n}\nif (!hasDateCondition(conditions)) {\n  throw new Error('createSchedule requires a date condition with a value');\n}\nawait createSchedule({ conditions });","typeGuard":"function isDateCondition(c) {\n  return c != null && c.field === 'date' &&\n    (typeof c.op === 'string' && c.value != null);\n}","tryCatchPattern":"try {\n  const id = await createSchedule({ conditions });\n} catch (e) {\n  if (e.message === 'A date condition is required to create a schedule') {\n    logger.error('Schedule conditions missing date condition', conditions);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always include a field:'date' condition in schedule creation payloads","Validate the full conditions array against the schedule schema before calling the API","Prefer creating schedules from the UI which enforces this structurally","Write an integration test asserting createSchedule rejects date-less conditions"],"tags":["schedule","validation","missing-condition"],"backgroundTag":"missing-date-condition","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}