Developer ToolsFree generatorPDF, Excel, Word exportMicrosoft Dynamics 365 Business Central

Business Central AL Event Subscriber Code Generator

Business Central customization is done with extensions that react to events instead of editing base code. This generator writes the subscriber codeunit and the EventSubscriber attribute so you do not have to remember the syntax.

Fill in

An ID in your extension range from app.json

Copy the parameter list from the publisher so signatures match exactly

Generated code
Download:

AL codeunit

codeunit 50100 "NTR Sales Post Subscribers"
{
    Access = Internal;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforePostSalesDoc', '', false, false)]
    local procedure CheckBeforePostSalesDoc(var SalesHeader: Record "Sales Header"; CommitIsSuppressed: Boolean; PreviewMode: Boolean; var HideProgressWindow: Boolean; var IsHandled: Boolean)
    begin
        // Add your logic here. Keep it small and avoid user dialogs in posting events.
    end;
}

Publisher names with spaces or hyphens must be quoted, as shown. Check the event signature in the publisher source (the Base Application is public on GitHub) because parameter names, order and var keywords must match. The last two boolean arguments are SkipOnMissingLicense and SkipOnMissingPermission, confirm against current AL documentation for your runtime version.

Extension design second opinion

Optionally ask for a short review of your event design before you build.

Optional. The tool and every export work without this. No spam.

How to use the generator

Fill in the object type and name of the publisher, the event name and the parameter list. Paste the parameter list from the publisher so the signature matches exactly. Copy the output into a new .al file in your extension, adjust the object ID to your range and add your logic inside begin and end. Build the extension with the AL Language extension for Visual Studio Code.

  • Find events by searching the Base Application source or the Event Recorder page
  • Keep the subscriber codeunit name unique with your prefix
  • Use a separate procedure per event for readability

Anatomy of the attribute

The EventSubscriber attribute takes the object type, the object, the event name, an element name used for field level events, and two Boolean values that control skipping when the license or permission is missing. For business events the element name is an empty string. For table events such as OnAfterValidateEvent, the element name is the field name. The procedure that follows must be local or global but not require parameters other than those published.

Good practice for subscribers

Subscribers run inside the posting transaction, so an error rolls back the document. Do not open dialogs, send mail or call slow web services inside posting events. Respect the IsHandled pattern: if the publisher offers IsHandled, check it first and set it only when you fully take over the logic. Wrap new behavior in a setup flag so it can be turned off without redeployment.

Common mistakes

Signature mismatches produce a compile error, so copy parameters exactly including var. Another mistake is subscribing to a broad table event like OnAfterInsertEvent and running heavy code. Developers also forget that events can be raised during preview posting, so check PreviewMode where relevant. Finally, never modify the Base Application, only extend it.

Frequently Asked Questions

How do I find the event I need?

Use the Event Recorder page in Business Central to record the events raised while you perform an action, or search the public Base Application source on GitHub for the codeunit and look for IntegrationEvent and BusinessEvent attributes.

What happens if my parameter list is wrong?

The AL compiler gives an error because the subscriber signature must match the published event. Names can differ in some cases, but the types, order and var modifiers must match, so copy from the publisher.

Can a subscriber change the outcome of posting?

Yes. Parameters passed by var can be changed, and an Error call stops the transaction. Use this carefully and document the behavior, because other extensions may subscribe to the same event.

Is this the same as C/AL triggers in NAV?

No. In classic NAV you edited code in base objects. In Business Central extensions you subscribe to published events and never change the base, which is what makes upgrades manageable.

If your extension work involves reports or integrations around posting, we can help design them with human approval on any write-back.