bcquality/microsoft/knowledge/error-handling/fielderror-vs-testfield.good.al
Jesper Schulz-Wedde c9d90ac605 Promote validated community knowledge
Move eight net-new rules into the Microsoft layer, remove six overlapping articles, and update review skill discovery and references.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0b130227-d418-4bc0-9e7d-ec6a37adf039
2026-07-14 14:14:07 +02:00

27 lines
860 B
AL

table 50122 "FieldError vs TestField Good"
{
fields
{
field(1; "No."; Code[20]) { }
field(2; "Posting Date"; Date) { }
field(3; "Amount"; Decimal) { }
}
procedure PostDocument()
begin
// TestField performs this simple presence check and raises only when
// the field is empty. Self-documenting prerequisite.
TestField("Posting Date");
// Business logic has already determined the value is invalid;
// FieldError raises a tailored, record-aware message with no
// condition of its own.
if IsAmountOutsideAllowedRange("Amount") then
FieldError("Amount", 'is outside the approved posting range');
end;
local procedure IsAmountOutsideAllowedRange(Value: Decimal): Boolean
begin
exit((Value < 0) or (Value > 1000000));
end;
}