mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 14:46:55 +01:00
Preserve independent event seams, cover loop-carried handled state, strengthen checkpoint and UI-handler fixtures, and align DeleteAll fallback guidance. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 10646e50-2d8b-4cca-b02b-dfa78629e6a1
48 lines
1.7 KiB
AL
48 lines
1.7 KiB
AL
// Demonstration-only AL. Not compiled by CI; illustrates the article.
|
|
codeunit 50241 "IsHandled Init Bad Sample"
|
|
{
|
|
procedure ApplyDiscounts(var SalesHeader: Record "Sales Header")
|
|
var
|
|
DiscountPct: Decimal;
|
|
IsHandled: Boolean;
|
|
begin
|
|
OnBeforeApplyHeaderDiscount(SalesHeader, DiscountPct, IsHandled);
|
|
if not IsHandled then
|
|
DiscountPct := 5;
|
|
|
|
// Bug: execution continues when the first event set IsHandled to true,
|
|
// and that stale value is passed to a different publisher.
|
|
OnBeforeApplyPaymentDiscount(SalesHeader, DiscountPct, IsHandled);
|
|
if not IsHandled then
|
|
DiscountPct += 2;
|
|
end;
|
|
|
|
procedure ApplyLineDiscounts(var SalesLine: Record "Sales Line")
|
|
var
|
|
LineIsHandled: Boolean;
|
|
begin
|
|
if SalesLine.FindSet() then
|
|
repeat
|
|
// Bug: the local initializes only once. A subscriber that handles
|
|
// one line leaves true for every later iteration.
|
|
OnBeforeApplyLineDiscount(SalesLine, LineIsHandled);
|
|
if not LineIsHandled then
|
|
SalesLine.Validate("Line Discount %", 5);
|
|
until SalesLine.Next() = 0;
|
|
end;
|
|
|
|
[IntegrationEvent(false, false)]
|
|
local procedure OnBeforeApplyHeaderDiscount(var SalesHeader: Record "Sales Header"; var DiscountPct: Decimal; var IsHandled: Boolean)
|
|
begin
|
|
end;
|
|
|
|
[IntegrationEvent(false, false)]
|
|
local procedure OnBeforeApplyPaymentDiscount(var SalesHeader: Record "Sales Header"; var DiscountPct: Decimal; var IsHandled: Boolean)
|
|
begin
|
|
end;
|
|
|
|
[IntegrationEvent(false, false)]
|
|
local procedure OnBeforeApplyLineDiscount(var SalesLine: Record "Sales Line"; var IsHandled: Boolean)
|
|
begin
|
|
end;
|
|
}
|