bcquality/custom/knowledge/architecture/pages-must-not-contain-business-logic.md
Michael Dieringer c4a9f8e88e update
2026-06-13 13:46:40 +02:00

1.5 KiB

bc-version domain keywords technologies countries application-area
all
architecture
page
trigger
onaction
modify
codeunit
logic
al
w1
all

Description

In CURABIS codebases, pages are pure presentation. Business logic, calculations, validations, and record modifications belong in codeunits — not in page triggers or actions. This is stricter than the general BC guidance and applies to all CURABIS PTE apps.

A page procedure that calculates a value and assigns it to a field, calls Rec.Modify() directly, or implements business rules is an architecture violation even if it compiles.

Exceptions:

  • Setup pages may read and write their own setup record directly.
  • The designated "Run Conversion" page may call the conversion codeunit directly.

Anti Pattern

// WRONG: calculation and Modify in a page action
trigger OnAction()
begin
    Rec."Total Amount" := Rec.Quantity * Rec."Unit Price";
    Rec."VAT Amount" := Rec."Total Amount" * 0.25;
    Rec.Modify();
end;
// WRONG: validation logic in page trigger
trigger OnValidate()
begin
    if Rec.Quantity < 0 then
        Error('Quantity cannot be negative');
    Rec."Total Amount" := Rec.Quantity * Rec."Unit Price";
end;

Best Practice

// CORRECT: page delegates to codeunit
trigger OnAction()
begin
    SVManagement.RecalculateLine(Rec);
end;
// CORRECT: validation belongs in table or codeunit
trigger OnValidate()
begin
    SVManagement.ValidateAndRecalculate(Rec);
end;

The codeunit owns the logic. The page owns the presentation.