{"record":{"id":"340c1980ebb1d660","repo":"hcengineering/platform","slug":"please-select-initial-state-space-340c19","errorCode":null,"errorMessage":"Please select initial state:${_space}","messagePattern":"Please select initial state:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/recruit-resources/src/components/CreateApplication.svelte","lineNumber":119,"sourceCode":"    modifiedBy: '' as PersonId,\n    startDate: null,\n    dueDate: null,\n    kind: '' as Ref<TaskType>,\n    isDone: false\n  }\n\n  const dispatch = createEventDispatcher()\n  const client = getClient()\n  const hierarchy = client.getHierarchy()\n  fillDefaults(hierarchy, doc, recruit.class.Applicant)\n\n  export function canClose (): boolean {\n    return (preserveCandidate || _candidate === undefined) && assignee === undefined\n  }\n\n  async function createApplication (): Promise<void> {\n    if (selectedState === undefined) {\n      throw new Error(`Please select initial state:${_space}`)\n    }\n    const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Applicant })\n    if (sequence === undefined) {\n      throw new Error('sequence object not found')\n    }\n    if (kind === undefined) {\n      throw new Error('kind is not specified')\n    }\n\n    const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)\n\n    const candidateInstance = await client.findOne(contact.class.Person, { _id: _candidate })\n    if (candidateInstance === undefined) {\n      throw new Error('contact not found')\n    }\n\n    const ops = client.apply(undefined, recruitId + '.Create.CreateApplication')\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/recruit-resources/src/components/CreateApplication.svelte#L101-L137","documentation":"Thrown in CreateApplication.svelte when `selectedState` is undefined at application creation time. An application must be placed into an initial state of the target vacancy/space, so the code refuses to proceed without one. The message includes the space name to help identify which project lacks a state selection.","triggerScenarios":"User submits the CreateApplication dialog without choosing an initial state; the target space's states failed to load so the selector stays empty; state filter for the space returns no done-less states.","commonSituations":"New vacancy whose state machine was not set up; UI not blocking submit when state dropdown untouched; states not migrated for a copied/merged space.","solutions":["Select an initial state in the dialog before creating the application","Ensure the target space has default states configured (inherit states from project type)","Disable the create button until selectedState is defined","Catch the error and show a picker prompt instead of throwing"],"exampleFix":"// before\nif (selectedState === undefined) {\n  throw new Error(`Please select initial state:${_space}`)\n}\n// after\nif (selectedState === undefined) {\n  ui.notify(`Please select an initial state for ${_space}`)\n  return\n}","handlingStrategy":"validation","validationCode":"if (selectedState === undefined) {\n  ui.notify(`Select an initial state for ${_space}`)\n  return\n}\nawait createApplication()","typeGuard":"function hasState (state: Ref<DomainState> | undefined): state is Ref<DomainState> {\n  return state !== undefined\n}","tryCatchPattern":"try {\n  await createApplication()\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Please select initial state')) {\n    ui.notify('Choose an initial state before creating the application.')\n  } else throw err\n}","preventionTips":["Disable create until a state is selected","Preselect the first/default state of the space","Ensure target spaces inherit states from their project type","Validate state availability when the space changes"],"tags":["validation","missing-selection","state-machine"],"backgroundTag":"required-field-missing","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}