If Event Subscriptions are the “listeners,” then Event Publishers are the “speakers.” They are what raise (trigger) events inside Business Central so other code can react. This blog explains everything from basics to practical use—with simple examples.
What is an Event Publisher?
An Event Publisher is a method in AL that raises an event using attributes like:
- [IntegrationEvent]
- [BusinessEvent]
It allows other developers (or your own extension) to subscribe and extend behavior.
Why Event Publishers Are Important
Without publishers:
- No extension points
- Hard-coded logic
- Difficult upgrades
With publishers:
- Clean extensibility
- Upgrade-safe design
- Loose coupling
- Reusable architecture
Simple Analogy
Think of a YouTube Live Stream:
- Publisher = Person streaming
- Subscribers = Viewers watching
- Publisher sends event → Subscribers react
Types of Event Publishers
1. Integration Events (Most Common)
Used for customization inside Business Central
[IntegrationEvent(IncludeSender : Boolean, GlobalVarAccess : Boolean)]
- Flexible
- Can expose internal logic
2. Business Events
Used for external integrations
[BusinessEvent(false)]
- Stable
- Used in Power Automate / APIs
Basic Syntax of Event Publisher
[IntegrationEvent(false, false)]
procedure OnAfterCustomerCreated(Customer: Record Customer)
begin
end;
This defines an event—but does NOT run automatically. You must call it manually
Calling (Raising) the Event
procedure CreateCustomer()
var
Customer: Record Customer;
begin
// Insert logic here
OnAfterCustomerCreated (Customer); // Event triggered
end;
Complete Example (Publisher + Subscriber)
Step 1: Create Publisher
codeunit 50100 CustomerPublisher
{
[IntegrationEvent(false, false)]
procedure OnAfterCustomerCreated(Customer: Record Customer)
begin
end;
procedure CreateCustomer()
var
Customer: Record Customer;
begin
Customer.Init();
Customer.Name := 'Test Customer';
Customer.Insert();
OnAfterCustomerCreated(Customer); // Raise event
end;
}
Step 2: Create Subscriber
codeunit 50101 CustomerSubscriber
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::CustomerPublisher, 'OnAfterCustomerCreated', '', false, false)]
local procedure HandleCustomerCreated(Customer: Record Customer)
begin
Message('Customer Created: %1', Customer.Name);
end;
}
Key Concepts You Must Understand
1. Publisher ≠ Subscriber
| Publisher | Subscriber |
| Raises event | Listens to event |
| Defines method | Implements reaction |
2. Event Does Nothing Alone
If no subscriber exists → nothing happens
Publisher just provides a hook
3. Multiple Subscribers Allowed
One event → Many subscribers
Each runs independently
Parameters Explained
[IntegrationEvent (false, false)]
| Parameter | Meaning |
| IncludeSender | Access to publisher object |
| GlobalVarAccess | Access global variables |
Real-World Use Cases
1. After Customer Creation
- Send email
- Log activity
- Sync to Azure SQL
2. Sales Posting
- Custom validation
- External API call
- Audit tracking
3. Workflow Triggers
- Notify approval system
- Trigger Power Automate
Common Beginner Mistakes
❌ Forgetting to call the event
✔ Always trigger manually
❌ Putting logic inside publisher
✔ Keep it clean—logic goes in subscribers
❌ Too many parameters
✔ Keep events simple
Best Practices
- Use clear naming: OnBefore…, OnAfter…
- Keep publishers lightweight
- Document your events
- Avoid breaking changes in published events
Quick Summary
- Event Publisher = raises event
- Defined using [IntegrationEvent] or [BusinessEvent]
- Must be called manually
- Enables clean extension of logic
- Works with Event Subscribers
Final Thoughts
Mastering Event Publishers means you can:
- Build scalable extensions
- Avoid modifying base code
- Design enterprise-grade solutions
It’s one of the most powerful patterns in Business Central development.