bcquality/microsoft/knowledge/data-modeling/validate-table-relation-false-suppresses-rename-propagation.good.al
Jesper Schulz-Wedde 42ff075793 Promote knowledge for Microsoft review skills
Move canonical knowledge for Microsoft-owned review domains into the Microsoft layer and document the skill/knowledge co-location policy.

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

Copilot-Session: 2a6ea875-d38e-4f30-aadb-0d606f9be231
2026-09-03 14:59:44 +02:00

70 lines
1.8 KiB
AL

table 50120 "Source Document"
{
fields
{
field(1; "No."; Code[20])
{
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "No.")
{
Clustered = true;
}
}
// "Source Key" below cannot declare a TableRelation, so the platform cannot
// repoint it. The owning table carries the relationship by hand.
trigger OnRename()
var
DocumentLink: Record "Document Link";
begin
// In OnRename, xRec holds the PREVIOUS primary key while Rec holds the new
// one — the one trigger where that is true regardless of what drove the rename.
DocumentLink.SetRange("Source Key", MakeSourceKey(xRec."No."));
if DocumentLink.FindSet(true) then
repeat
DocumentLink."Source Key" := MakeSourceKey(Rec."No.");
DocumentLink.Modify(true);
until DocumentLink.Next() = 0;
end;
local procedure MakeSourceKey(DocumentNo: Code[20]): Code[50]
begin
exit(StrSubstNo('DOC|%1', DocumentNo));
end;
}
table 50121 "Document Link"
{
fields
{
field(1; "Entry No."; Integer)
{
DataClassification = CustomerContent;
}
// Default ValidateTableRelation: the platform repoints this on rename.
field(2; "Document No."; Code[20])
{
DataClassification = CustomerContent;
TableRelation = "Source Document"."No.";
}
// Composite value — no TableRelation can express it, so the parent's
// OnRename above maintains it explicitly.
field(3; "Source Key"; Code[50])
{
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "Entry No.")
{
Clustered = true;
}
}
}