bcquality/microsoft/knowledge/events/use-ishandled-to-make-base-behaviour-overridable.bad.al
Jesper Schulz-Wedde 54ddd8ecc2 Add events knowledge domain and review leaf skill
Add a new `events` knowledge domain covering AL events & subscribers,
wired into the AL review pipeline.

- 3 atomic articles (+ .good.al/.bad.al samples) under
  microsoft/knowledge/events/: the IsHandled override pattern, thin
  OnBefore/OnAfter integration-event publishers, and static vs manual
  subscribers.
- New leaf skill microsoft/skills/review/al-events-review.md sourcing the
  events domain.
- Wired into microsoft/skills/review/al-code-review.md (sub-skills + Source
  + description) and README.md (leaf-skill count + domain list).

AL event syntax verified against Microsoft Learn. Samples are
demonstration-only (not compiled by CI). Additive change; no contract change.

Part of #34.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-25 11:58:58 +02:00

38 lines
1.3 KiB
AL

// Demonstration-only AL. Not compiled by CI; illustrates the article.
// Anti-pattern 1: no OnBefore/IsHandled hook. A partner cannot replace this
// rule without overwriting base code, so the behaviour is not extensible.
codeunit 50222 "Shipping Charge NoHook Bad"
{
procedure CalculateShippingCharge(OrderAmount: Decimal) Charge: Decimal
begin
if OrderAmount >= 1000 then
Charge := 0
else
Charge := 49;
end;
}
// Anti-pattern 2: the hook exists but the 'if IsHandled then exit;' guard is
// missing, so the default logic still runs after a subscriber handled the call.
codeunit 50223 "Shipping Charge Guard Bad"
{
procedure CalculateShippingCharge(OrderAmount: Decimal) Charge: Decimal
var
IsHandled: Boolean;
begin
OnBeforeCalculateShippingCharge(OrderAmount, Charge, IsHandled);
// Bug: no 'if IsHandled then exit;' here. Even when a subscriber set
// Charge and IsHandled := true, the default below overwrites the result.
if OrderAmount >= 1000 then
Charge := 0
else
Charge := 49;
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeCalculateShippingCharge(OrderAmount: Decimal; var Charge: Decimal; var IsHandled: Boolean)
begin
end;
}