The AL developer environment is evolving with frequent updates. To stay up to date on the latest information and announcements, follow us on the Dynamics NAV Team Blog.

Publishing Events

The first phase of implementing an event is publishing the event. Publishing an event exposes it in the application. This provides hook up points for subscribers to register to the event, and eventually handle the event if it is raised. An event is published by adding AL method that is specifically set up as an event publisher.

  • Business and integration events require that you manually create an event publisher method for each event that you want to publish. An event publisher method declares the event in the application and makes it available for subscription; however, it does not raise the event. After an event is published, you can raise it in your application, as needed, from where event subscribers can react and handle the event.

  • Trigger events, on the other hand, do not require that you create publisher methods. Trigger events are by predefined event publisher methods that are called automatically at runtime. This means that trigger events are readily available to subscribers by default.

Creating an event publisher method to publish business and integration events

You create an event publisher method the same way you create any method in AL, except that there are specific properties that you set to make it an event publisher. Additionally, an event publisher method has the following requirements and restrictions that you must follow, otherwise you not able to compile your code changes:

  • An event publisher method cannot include any code except comments.

  • An event publisher method cannot have a return value, variables, or text constants.

The following procedure provides an outline of the tasks that are involved in creating an event publisher method for declaring an event.

To create an event publisher method

  1. Decide where you want to include the event publisher method.

    You can include an event publisher method in the AL code of any object type, such as codeunit, page, or table. You can create a new object or use and existing object.


    If you include the event publisher method in a page object, the page must have a source table. Otherwise, you cannot successfully create an event subscriber method to subscribe to the event.

  2. Add a AL method to the object.

    If you do not want to make the event available to event subscribers, make it a local method by affixing it with local.

    You should give the method a name that has the format On[Event], where [Event] is text that indicates what occurred, such as OnAddressLineChanged.

  3. Decorate the method with the either the Integration attribute or Business attribute as follows:

    [Integration(IncludeSender : Boolean, GlobalVarAccess : Boolean)] 


    [Business(IncludeSender : Boolean)] 


    Use the teventint snippet for an integration event or the teventbus snippet for a business event to get started.

    For more information about integration and business events, see Event Types.

  4. Add parameters to the method as needed.

    You can include as many parameters of any type as necessary.

    Make sure to expose enough information as parameters to enable subscriber methods to add value to the application. On the other hand, especially with business events, do not expose unnecessary parameters that may constrain you from changing or extending methodally in the future.

You can now add code to the application that raises the event by calling the event publisher method. You can also create subscriber methods that handle the event when it is raised.


This example creates the codeunit 7000001 MyPublisher to publish an integration event. The event is published by adding the global method called OnAddressLineChanged. The event takes a single text data type parameter.


This example is part of a larger, simple scenario where when users change the address of a customer on the page 21 Customer Card, you want to check that the address does not include a plus sign (+). If it does, you want to display a message. To accomplish this, you will publish an event that is raised when the Address field on Customer Card is changed, and add an event subscriber method to that includes logic that checks the address value and returns a message to the user if it contains a plus sign.

codeunit 70000001 MyPublishers
    [Integration(false, false)]
    procedure OnAddressLineChanged(line : Text[100]);

The next step would be to raise this event in the application. To see an example for how this event is raised, go to Raising Event Example.

See Also

Raising Events
Subscribing to Events
Events Dynamics 365