bcquality/microsoft/knowledge/performance/avoid-repeating-unchanged-validation.good.al
Jesper Schulz-Wedde af94c135ad Add BC performance knowledge from OptimAL learnings
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-25 14:13:37 +02:00

38 lines
918 B
AL

// Quantity validation depends only on Quantity and Unit Price in this demo.
table 50371 "Perf Validated Line"
{
DataClassification = CustomerContent;
fields
{
field(1; "Line No."; Integer) { }
field(2; Quantity; Decimal)
{
trigger OnValidate()
begin
Amount := Quantity * "Unit Price";
end;
}
field(3; "Unit Price"; Decimal) { }
field(4; Amount; Decimal) { }
field(5; Note; Text[100]) { }
}
keys
{
key(PK; "Line No.") { Clustered = true; }
}
}
codeunit 50372 "Perf Validation Good"
{
procedure UpdateLine(LineNo: Integer; NewQuantity: Decimal; NewNote: Text[100])
var
Line: Record "Perf Validated Line";
begin
Line.Get(LineNo);
Line.Validate(Quantity, NewQuantity);
Line.Note := NewNote;
Line.Modify(false);
end;
}