bcquality/microsoft/knowledge/privacy/register-owned-log-tables-for-retention-policies.good.al
Jeremy Vyska 2f3e5afac1 Add retention policy knowledge to the privacy domain
Two articles covering retention policies for extension-owned tables,
the gap that lets high-volume log tables grow unbounded:

- register-owned-log-tables-for-retention-policies: an extension's own
  log tables must be added to the allowed-tables list from install AND
  upgrade code, guarded by IsAllowedTable plus an upgrade tag, with a
  mandatory minimum retention where audit needs one.
- ship-a-default-retention-policy-setup: registration only makes a table
  selectable; nothing is deleted until a Retention Policy Setup record
  exists, so ship one (disabled by default) as the platform's own
  Retention Policy Installer does.

Each ships good/bad AL samples. Claims verified against the BC admin
docs and the Retention Policy module in microsoft/BCApps.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011gvTjm746MtJEVWeRTbG46
2026-09-10 12:58:26 +02:00

55 lines
1.5 KiB
AL

codeunit 50560 "Contoso Reten. Pol. Setup"
{
Access = Internal;
procedure AddAllowedTables()
var
ContosoActivityLog: Record "Contoso Activity Log";
RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables";
UpgradeTag: Codeunit "Upgrade Tag";
begin
if UpgradeTag.HasUpgradeTag(AllowedTableTag()) then
exit;
if not RetenPolAllowedTables.IsAllowedTable(Database::"Contoso Activity Log") then
RetenPolAllowedTables.AddAllowedTable(
Database::"Contoso Activity Log",
ContosoActivityLog.FieldNo(SystemCreatedAt),
28); // support cases need at least four weeks of log history
UpgradeTag.SetUpgradeTag(AllowedTableTag());
end;
local procedure AllowedTableTag(): Code[250]
begin
exit('Contoso-ActivityLogAllowedTable-20260910');
end;
}
codeunit 50561 "Contoso Reten. Pol. Install"
{
Subtype = Install;
Access = Internal;
trigger OnInstallAppPerCompany()
var
ContosoRetenPolSetup: Codeunit "Contoso Reten. Pol. Setup";
begin
ContosoRetenPolSetup.AddAllowedTables();
end;
}
codeunit 50562 "Contoso Reten. Pol. Upgrade"
{
Subtype = Upgrade;
Access = Internal;
// Install code does not run on upgrade, so tenants that already have the
// app get their registration here.
trigger OnUpgradePerCompany()
var
ContosoRetenPolSetup: Codeunit "Contoso Reten. Pol. Setup";
begin
ContosoRetenPolSetup.AddAllowedTables();
end;
}