Design consistent document flows

Completed

A Business Central document combines header and line tables, a document page, a line subpage, status transitions, and processing logic. Treat these parts as one stateful pattern rather than independent objects.

Synchronize header and line identity

The header's number identifies the document. Each line uses the document number and a line number as its compound primary key. The document page connects the records through SubPageLink:

part(Lines; "Inspection Request Subpage")
{
    ApplicationArea = All;
    SubPageLink = "Document No." = field("No.");
    UpdatePropagation = Both;
}

Set the line field's TableRelation to the header number. When the header is deleted through an allowed path, delete its lines in the header table trigger so orphan lines don't remain.

Make document state explicit

Use an enum for states such as Open and Released. Open documents allow edits. Release validates the header and lines, then changes the status. Reopen returns a released document to an editable state. Processing accepts only a released document.

The document page reflects this state by controlling editability and action availability. The line table also tests that the related header is open before insert, modify, or delete operations. This table-level check protects the rule when another page or an integration changes a line.

Centralize Release, Reopen, and Process procedures in a management codeunit. This approach keeps transitions consistent and provides one entry point for later events, telemetry, tests, or additional validation.

Separate capture from results

Processing validates the released document, creates permanent entries, and then removes the consumed header and lines. Copy fields that history requires, including the source document number, master number, description, date, and line details.

Don't let users edit the resulting entries through ordinary pages. If the business needs corrections, design an explicit reversal or correction flow. This separation preserves the meaning of both the source document and its processed result.

For more information, see Page object, SubPageLink property, and Codeunit object.