IsHandled parameter assignment (PC0023)
In event subscriber procedures that implement the IsHandled pattern, the IsHandled parameter should only be set to true, never to false. Setting it to false would override decisions made by earlier subscribers.
Example
The following code incorrectly sets IsHandled to false:
codeunit 50100 MyCodeunit
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforePostSalesDoc', '', false, false)]
local procedure OnBeforePostSalesDoc(var IsHandled: Boolean)
begin
IsHandled := false; // IsHandled parameter assignment [PC0023]
end;
}
To fix this, only set IsHandled to true when handling the event:
codeunit 50100 MyCodeunit
{
[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;
}
See also
- PC0011 - EventPublisher IsHandled by var