bcquality/microsoft/knowledge/privacy/ship-a-default-retention-policy-setup.good.al
Jeremy Vyska 4bef582ffe Address review feedback on retention policy knowledge
- Scope both articles to bc-version [17..] (retention policies shipped in v17).
- Allowed-tables sample: add OnRefreshAllowedTables subscriber with a
  ForceUpdate path; the upgrade tag now gates one-time setup only.
- Default-policy sample: use Retention Policy Setup.FindOrCreateRetentionPeriod
  instead of a hand-rolled lookup-then-insert that can collide on code.
- Anti-pattern now keys on append-only tables rather than table names.
- al-privacy-review: add retention-policy tokens and deterministic routing
  for both articles, with a bounded per-table text search for delete and
  registration paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 09:41:25 +02:00

33 lines
1.3 KiB
AL

codeunit 50564 "Contoso Reten. Pol. Default"
{
Access = Internal;
procedure CreateDefaultPolicy()
var
RetentionPolicySetup: Record "Retention Policy Setup";
RetentionPolicySetupMgt: Codeunit "Retention Policy Setup";
UpgradeTag: Codeunit "Upgrade Tag";
begin
// Created once per company: an administrator who deletes the policy
// does not get it back on the next upgrade.
if UpgradeTag.HasUpgradeTag(DefaultPolicyTag()) then
exit;
if not RetentionPolicySetup.Get(Database::"Contoso Activity Log") then begin
RetentionPolicySetup.Validate("Table Id", Database::"Contoso Activity Log");
RetentionPolicySetup.Validate("Apply to all records", true);
RetentionPolicySetup.Validate(
"Retention Period",
RetentionPolicySetupMgt.FindOrCreateRetentionPeriod("Retention Period Enum"::"6 Months"));
RetentionPolicySetup.Validate(Enabled, false); // the administrator opts in to deletion
RetentionPolicySetup.Insert(true);
end;
UpgradeTag.SetUpgradeTag(DefaultPolicyTag());
end;
local procedure DefaultPolicyTag(): Code[250]
begin
exit('Contoso-ActivityLogDefaultPolicy-20260910');
end;
}