Incorrect 'IsHandled' parameter assignment
Business Central’s event model allows multiple subscribers to react to the same event. When an event uses the IsHandled pattern, a subscriber that has handled the event sets IsHandled to true so that later subscribers can check the flag and exit early. This contract depends on every subscriber only ever raising the flag — never lowering it.
When a subscriber assigns false to IsHandled, or assigns a variable or expression that can evaluate to false, it silently undoes whatever an earlier subscriber decided. The earlier subscriber’s work still happened — records may already be modified, external calls may already have been made — but the publisher now behaves as if no one handled the event. The result is duplicated logic, contradictory state, or runtime errors that surface far from their cause.
Only set IsHandled to true, or use the self-guarded or pattern to preserve the flag while adding your own condition.
Example
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforePostSalesDoc', '', false, false)]
local procedure OnBeforePostSalesDoc(var IsHandled: Boolean)
var
MyCondition: Boolean;
begin
MyCondition := CheckSomething();
IsHandled := MyCondition; // Incorrect 'IsHandled' parameter assignment [PC0023]
end;The variable MyCondition may evaluate to false, resetting any earlier subscriber’s decision. Set IsHandled to true explicitly, or preserve the existing value with or:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforePostSalesDoc', '', false, false)]
local procedure OnBeforePostSalesDoc(var IsHandled: Boolean)
begin
if not IsHandled then begin
// Handle the event
IsHandled := true;
end;
end;When IsHandled should be set conditionally while preserving decisions from earlier subscribers, use the self-guarded or pattern:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforePostSalesDoc', '', false, false)]
local procedure OnBeforePostSalesDoc(var IsHandled: Boolean)
begin
IsHandled := IsHandled or CheckSomething();
end;When the diagnostic is reported
IsHandled(orHandled) is assignedfalsedirectly.IsHandledis assigned a variable or expression that may evaluate tofalse(e.g.IsHandled := MyCondition;).IsHandledis passed as avarparameter to another procedure, where it could be reset.IsHandledis assigned withand(e.g.IsHandled := IsHandled and SomeCondition;), which can lower the flag.
The diagnostic is suppressed when the assignment is preceded by if IsHandled then exit;, since the subscriber has already deferred to earlier decisions, or when the self-guarded or pattern is used (IsHandled := IsHandled or ...).
See also
- PC0011 — Handled parameters in event signatures should be passed by var
- Using the IsHandled pattern for events on Microsoft Learn