mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-08-07 09:56:52 +01:00
Add 12 atomic knowledge articles under microsoft/knowledge/events covering general AL event-design best practices: IsHandled initialization and OnAfter preservation, appending new event parameters, position-based event naming, reusing/extending events, avoiding per-iteration publishing, Temp-prefixing temporary record parameters, unabbreviated parameter names, preferring the this keyword over IncludeSender, avoiding loosely typed parameters, not mutating existing event contracts, and not bypassing critical operations with IsHandled. Each article ships a .good.al and .bad.al demonstration sample (object IDs 50240-50296; not compiled by CI). Extend the al-events-review leaf Worklist with one targeted check per new rule. Additive only; no contract or wiring change (events leaf already wired). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
38 lines
1.3 KiB
AL
38 lines
1.3 KiB
AL
// Demonstration-only AL. Not compiled by CI; illustrates the article.
|
|
codeunit 50295 "Critical Op Good Sample"
|
|
{
|
|
procedure PostInvoice(var SalesHeader: Record "Sales Header")
|
|
var
|
|
DiscountAmount: Decimal;
|
|
IsHandled: Boolean;
|
|
begin
|
|
// IsHandled guards only a safe, side-effect-free calculation.
|
|
IsHandled := false;
|
|
OnBeforeCalculateInvoiceDiscount(SalesHeader, DiscountAmount, IsHandled);
|
|
if not IsHandled then
|
|
DiscountAmount := 10;
|
|
SalesHeader."Invoice Discount Amount" := DiscountAmount;
|
|
|
|
// Critical operations always run; no subscriber can bypass them.
|
|
CreateCustomerLedgerEntry(SalesHeader);
|
|
SalesHeader.Status := SalesHeader.Status::Released;
|
|
SalesHeader.Modify(true);
|
|
|
|
OnAfterPostInvoice(SalesHeader);
|
|
end;
|
|
|
|
local procedure CreateCustomerLedgerEntry(var SalesHeader: Record "Sales Header")
|
|
begin
|
|
// Posts the customer ledger entry (critical; must never be skipped).
|
|
end;
|
|
|
|
[IntegrationEvent(false, false)]
|
|
local procedure OnBeforeCalculateInvoiceDiscount(var SalesHeader: Record "Sales Header"; var DiscountAmount: Decimal; var IsHandled: Boolean)
|
|
begin
|
|
end;
|
|
|
|
[IntegrationEvent(false, false)]
|
|
local procedure OnAfterPostInvoice(var SalesHeader: Record "Sales Header")
|
|
begin
|
|
end;
|
|
}
|