편집

다음을 통해 공유


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

For more information about the different event types, see Event Types.

When you set the IncludeSender argument to true, the signature of event subscriber methods that subscribe to the published event automatically include a VAR parameter for the published event 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;
}

For more information about isolated events, see Isolated Events.

Example

This example publishes a business type event by using the OnAddressLineChanged method. The method takes a single text data type 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