Select Page
Beginner’s Guide to Event Subscriptions in Microsoft Dynamics 365 Business Central

May 7, 2026

If you’re starting your journey in Business Central development, one concept you must understand early is Event Subscriptions. It’s the backbone of writing clean, upgrade-safe customizations using AL.

This guide walks you from zero to confident beginner, with clear examples and practical tips.

What Are Event Subscriptions?

Event Subscriptions allow your code to listen to events happening inside Business Central and execute custom logic—without modifying the original Microsoft code.

 Think of it like this:

  • Business Central raises an event → “Something happened”
  • Your code subscribes → “Do something when it happens”

Why Event Subscriptions Matter

  • Before events, developers had to modify base code (bad idea ).

With events:

  • No base code changes
  • Safe upgrades
  • Clean architecture
  •  Easy debugging

Simple Real-Life Analogy

Imagine a doorbell system:

  • Someone presses the bell → Event triggered
  • You hear it → Subscriber reacts

That’s exactly how Event Subscriptions work.

Core Components

  1. Event Subscriber: Your custom code that listens and reacts
  2. Event Publisher: The object that raises the event (Check Next Blog)

Types of Events in Business Central

 1. Table Events

Triggered when data changes

Examples:

  • OnAfterInsertEvent
  • OnBeforeModifyEvent

 2. Page Events

Triggered from UI actions

Examples:

  • OnOpenPageEvent
  • OnClosePageEvent

 3. Integration Events (Custom)

Defined by developers using:

[IntegrationEvent (false, false)]

Your First Event Subscriber (Step-by-Step)

Let’s create a simple example:

Show a message when a Customer is created

Step 1: Create Codeunit

codeunit 50100 CustomerSubscriber
{

 Step 2: Add Event Subscriber

    [EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterInsertEvent', '', false, false)]
    local procedure OnCustomerCreated(var Rec: Record Customer)
    begin
        Message('Customer Created: %1', Rec.Name);
    end;
}

What’s Happening Here?

PartMeaning
ObjectType::TableWe listen to a table
Database::CustomerCustomer table
OnAfterInsertEventTrigger after insert
RecThe inserted record

 Understanding EventSubscriber Parameters

[EventSubscriber(ObjectType, Object, EventName, ElementName, SkipOnMissingLicense, SkipOnMissingPermission)]

Explained:

  • ObjectType → Table / Page / Codeunit
  • Object → Target object
  • EventName → Which event
  • ElementName → Usually blank
  • Skip flags → Error handling

Intermediate Example (Real Use Case)

Automatically log when a Sales Order is posted

Subscriber:

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', false, false)]
local procedure AfterSalesPost(SalesHeader: Record "Sales Header")
begin
    Message('Sales Order Posted: %1', SalesHeader."No.");
end;

 Creating Your Own Events

Sometimes, you need custom events.

Publisher:

[IntegrationEvent(false, false)]
procedure OnAfterCustomerValidated(Customer: Record Customer)
begin
end;

Subscriber:

[EventSubscriber(ObjectType::Codeunit, Codeunit::MyCodeunit, 'OnAfterCustomerValidated', '', false, false)]
local procedure HandleCustomEvent(Customer: Record Customer)
begin
    Message('Custom event triggered for %1', Customer.Name);
end;

Debugging Event Subscriptions

Business Central provides a built-in tool: Event Recorder

How to use:

  1. Search → Event Recorder
  2. Start recording
  3. Perform action
  4. Stop recording
  5. See all triggered events

Common Mistakes Beginners Make

❌ Writing heavy logic inside subscribers
✔ Keep it lightweight

❌ Not using var where needed
✔ Understand record passing

❌ Ignoring performance
✔ Events can run frequently

Best Practices

  • Use meaningful codeunit names
  • Keep one responsibility per subscriber
  • Add logging if needed
  • Use TryFunction for safety
  • Avoid UI (Message) in production

Real-World Use Cases

  • Auto-create ledger entries
  • Sync data to Azure SQL
  • Validate business rules
  • Trigger workflows
  • Send notifications

When Should You Use Event Subscriptions?

Use them when:

  • You want to extend standard behavior
  • You don’t want to modify base code
  • You need clean and scalable logic

Final Thoughts

Event Subscriptions are not optional in modern Business Central development—they are essential.

Once you master this, you can:

  • Build upgrade-safe extensions
  • Integrate with external systems
  • Customize Business Central professionally