Edit

BusinessEvent attribute

Version: Available or changed with runtime version 1.0.

Specifies that the method is published as a business type event.

Applies to

  • Method

Syntax

[BusinessEvent(IncludeSender: Boolean [, Isolated: Boolean])]

Arguments

IncludeSender
 Type: Boolean
Specifies that the firing instance of the object is available as a parameter to subscribers of that event.

[Optional] Isolated
 Type: Boolean
Specifies if event subscribers should be invoked in an isolated transaction.

Snippet support

Typing the shortcut teventbus will create the basic BusinessEvent attribute syntax when using the AL Language extension for Microsoft Dynamics 365 Business Central in Visual Studio Code.

Remarks

Learn more about the different event types in Event types.

When you set IncludeSender to true, an event subscriber can declare a sender parameter that references the publishing object, as shown in the following example:

codeunit 50100 MyPublishingCodeunit
{
    [BusinessEvent(true)]
    procedure MyBusinessEvent()
    begin
    end;
}

codeunit 50101 MySubscribingCodeunit
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::MyPublishingCodeunit, 'MyBusinessEvent', '', true, true)]
    local procedure MySubscriber(Sender: Codeunit MyPublishingCodeunit)
    begin
        // My subscriber code
    end;
}

Learn more about isolated events in Isolated events.

Example

This example publishes a business type event by using the OnAddressLineChanged method. The method takes one Text parameter. The IncludeSender argument is set to false.

[BusinessEvent(false)]
procedure OnAddressLineChanged(Line: Text[100])
begin
end;

AL method reference
Events in AL
Publishing events
Raising events
Subscribing to events
Isolated events
Method attributes