cardinal

Record lifecycle

What runs when a Record is saved, submitted, cancelled or amended.

Every write to a Record runs a fixed order of hooks inside one database transaction. The request or job owns that transaction, so record code never commits. Mail, realtime updates and jobs go out only after the commit.

Saving

A new Record runs these steps in order:

before_insert → naming → before_validate → validate → before_save
→ write (optimistic lock, child rows) → after_insert → on_update → on_change

A save of an existing Record skips before_insert, naming and after_insert.

The write checks modified. If someone else saved the Record after you opened it, your save fails with a 409 TimestampMismatch and the desk asks you to reload.

Docstatus

A RecType with is_submittable has three states.

docstatusStateWhat you can do
0DraftEdit, save, submit, discard
1SubmittedEdit only fields marked allow_on_submit, cancel
2CancelledAmend. No other change

A RecType that is not submittable keeps every Record at 0.

Each action

ActionMovesHooks before the writeHooks after the write
Insert→ 0before_insert, naming, before_validate, validate, before_saveafter_insert, on_update, on_change
Save0 → 0before_validate, validate, before_saveon_update, on_change
Submit0 → 1before_validate, validate, before_submiton_update, on_submit, on_change
Update after submit1 → 1before_update_after_submiton_update_after_submit, on_change
Cancel1 → 2before_cancelon_cancel, back-link check, on_change
Discard0 → 2before_discardon_discard, on_change

Any other move is refused with bad_docstatus. A cancelled Record takes no save, and a draft cannot be cancelled.

Cancel checks for submitted Records that still link to this one. If any exist, the cancel fails with LinkExists and lists them, up to 20 per field. Cancel those first.

Sales Invoice SINV-0001 (submitted) → links to → Sales Order SO-0001
Cancel SO-0001 → refused: SINV-0001 links to it

Amend

Amend copies a cancelled Record into a new draft with amended_from set to the source. By default the copy is named <source>-1, and an amendment of SO-0001-1 becomes SO-0001-2. Record Naming Settings can switch this to the RecType's normal naming rule. A cancelled Record can be amended only once.

SO-0001 (submitted) → Cancel → SO-0001 (cancelled) → Amend → SO-0001-1 (draft) → Submit

Versions

A RecType with track_changes writes a Version on every save that changes something. The form's timeline shows each change as Label: old → new.

On this page