bcquality/microsoft/knowledge/testing/recordref-open-temp-parameter-defeats-real-table-checks.bad.al
Michael Dieringer 260d064ece Add TableRelation field-length and RecordRef.Open Temp knowledge
- data-modeling: tablerelation-field-length-must-match-related-field
  (exact length for unconditional relations, at least the longest target
  when all relations are conditional; no compile-time diagnostic)
- testing: recordref-open-temp-parameter-defeats-real-table-checks
  (a temp-opened RecordRef is empty, so existence/uniqueness checks on it
  never see persisted rows; cross-links use-generateguid article)
- Wire both into the review leaves and register the fixture pairs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 23:18:10 +02:00

21 lines
824 B
AL

codeunit 50150 "Sample Payment Terms Codes"
{
procedure GenerateUnusedPaymentTermsCode(): Code[10]
var
PaymentTerms: Record "Payment Terms";
LibraryUtility: Codeunit "Library - Utility";
RecRef: RecordRef;
FieldRef: FieldRef;
NewCode: Code[10];
begin
// Temp = true: RecRef is an empty temporary instance, so IsEmpty()
// is true on the first pass and existing Payment Terms are never seen.
RecRef.Open(Database::"Payment Terms", true, CompanyName());
FieldRef := RecRef.Field(PaymentTerms.FieldNo(Code));
repeat
NewCode := CopyStr(LibraryUtility.GenerateRandomXMLText(MaxStrLen(NewCode)), 1, MaxStrLen(NewCode));
FieldRef.SetRange(NewCode);
until RecRef.IsEmpty();
exit(NewCode);
end;
}