mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 14:46:55 +01:00
Add an events article with compiled good/bad samples: GetDatabaseTableTriggerSetup (Global Triggers) and OnAfterGetDatabaseTableTriggerSetup (GlobalTriggerManagement) share four var Booleans across all subscribers, which run in no particular order. Assigning false, or a lookup result without or-ing in the current value, clears flags other features set (Dataverse sync, API webhooks, data archive, and, for direct Global Triggers subscribers, the change log). Recommends the codeunit 49 integration events per Learn's guidance on system codeunits 2000000001..2000000010 and handler-side table filtering. Wired into al-events-review tokens and an event-design check, with carve-outs for conditional := true, Flag := Flag or ..., and the no-op "if not Flag then Flag := false" found in BCApps. Registered in the events review-fixtures override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
1.9 KiB
AL
65 lines
1.9 KiB
AL
codeunit 50112 "Change Tracking Subscr. Good"
|
|
{
|
|
// Self-contained demonstration of the best practice. Not derived from base-app source.
|
|
[EventSubscriber(ObjectType::Codeunit, Codeunit::GlobalTriggerManagement, OnAfterGetDatabaseTableTriggerSetup, '', false, false)]
|
|
local procedure OptInTrackedTables(TableId: Integer; var OnDatabaseInsert: Boolean; var OnDatabaseModify: Boolean; var OnDatabaseDelete: Boolean; var OnDatabaseRename: Boolean)
|
|
var
|
|
TrackedTable: Record "Tracked Table Good";
|
|
begin
|
|
// Only ever turn flags on; flags set by other features stay untouched.
|
|
if not TrackedTable.Get(TableId) then
|
|
exit;
|
|
OnDatabaseModify := true;
|
|
OnDatabaseDelete := true;
|
|
end;
|
|
|
|
[EventSubscriber(ObjectType::Codeunit, Codeunit::GlobalTriggerManagement, OnAfterOnDatabaseModify, '', false, false)]
|
|
local procedure LogModify(RecRef: RecordRef)
|
|
var
|
|
TrackedTable: Record "Tracked Table Good";
|
|
TrackedChange: Record "Tracked Change Good";
|
|
begin
|
|
// The event also fires for tables other features opted in.
|
|
if RecRef.IsTemporary() then
|
|
exit;
|
|
if not TrackedTable.Get(RecRef.Number()) then
|
|
exit;
|
|
|
|
TrackedChange.Init();
|
|
TrackedChange."Table No." := RecRef.Number();
|
|
TrackedChange."Record ID" := RecRef.RecordId();
|
|
TrackedChange.Insert();
|
|
end;
|
|
}
|
|
|
|
table 50112 "Tracked Table Good"
|
|
{
|
|
DataClassification = SystemMetadata;
|
|
|
|
fields
|
|
{
|
|
field(1; "Table No."; Integer) { }
|
|
}
|
|
|
|
keys
|
|
{
|
|
key(PK; "Table No.") { Clustered = true; }
|
|
}
|
|
}
|
|
|
|
table 50113 "Tracked Change Good"
|
|
{
|
|
DataClassification = SystemMetadata;
|
|
|
|
fields
|
|
{
|
|
field(1; "Entry No."; Integer) { AutoIncrement = true; }
|
|
field(2; "Table No."; Integer) { }
|
|
field(3; "Record ID"; RecordId) { }
|
|
}
|
|
|
|
keys
|
|
{
|
|
key(PK; "Entry No.") { Clustered = true; }
|
|
}
|
|
}
|