Handled parameters in event signatures should be passed by var

Properties
PC0011 Warning Design Code Fix Ignore Obsolete

The IsHandled pattern relies on subscribers setting the IsHandled parameter to true to signal that the event was handled. For this to work, the publisher must pass the parameter by reference. Without var, the parameter is passed by value — the subscriber receives a copy, sets it to true, and the change is silently discarded. Back in the publisher, IsHandled is still false, so the default code path runs regardless of what the subscriber did.

Add the var keyword to the handled parameter in the event publisher signature. The companion rule PC0010 checks the other side: that subscribers match the publisher’s var declaration.

Example

codeunit 50100 "Sales Document Management"
{
    [IntegrationEvent(false, false)]
    local procedure OnBeforePostSalesDocument(var SalesHeader: Record "Sales Header"; IsHandled: Boolean) // Handled parameters in event signatures should be passed by var [PC0011]
    begin
    end;
}

Add var to the handled parameter:

codeunit 50100 "Sales Document Management"
{
    [IntegrationEvent(false, false)]
    local procedure OnBeforePostSalesDocument(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)
    begin
    end;
}

When the diagnostic is reported

  • The parameter is named IsHandled or Handled (case-insensitive).
  • The parameter type is Boolean.
  • The method is decorated with an event attribute (IntegrationEvent, BusinessEvent, or InternalEvent).

Code fix

Adds the var keyword to the handled parameter.

See also