AL events and integration patterns
By Emil Björk · Microsoft business apps consultant, Gothenburg
How AL events let extensions hook into Business Central — business events, integration events, subscriber patterns, and what to avoid.
On this page (6)
Events are the heart of AL extension architecture. They let your code run when Microsoft's code (or another extension's) reaches a defined point, without you modifying anyone else's source. Used well, they keep extensions upgrade-safe; used badly, they create invisible coupling across the codebase.
Two kinds of events
Business events are domain-level publications — "OnAfterPostSalesDocument", "OnAfterInsertCustomer" — declared by Microsoft on its standard objects. Integration events are custom publications declared by an extension when it wants to be extensible itself: an ISV's app might publish OnBeforeCalculateLineDiscount so customers can layer their own discounting rules.
Subscribers
A subscriber is a procedure in a codeunit decorated with [EventSubscriber(...)], naming the publisher object and the event. The compiler binds it at install time. When the publisher raises the event, every subscriber runs, in undefined order, in the same transaction.
OnBefore vs OnAfter
OnBefore events run before the action and can suppress or modify the operation (typically via a var IsHandled parameter). OnAfter events run after the action completes and are the right place for follow-on processing — sending an email, calling an integration, writing to a log.
Manual vs automatic binding
Subscribers can bind automatically (the default) or manually. Manual binding is for cases where the subscriber should run only when explicitly activated — for tests, or for per-tenant feature toggles. Manual subscribers are bound at runtime with BindSubscription.
Conditional subscription
A subscriber attribute can include a property filter so the subscriber only runs when a property on the publisher record matches a value — useful to scope cross-extension behaviour.
Common patterns.
- Add a field to a posted document: subscribe to
OnAfterCopy...between unposted and posted records to carry the value across. - Validate before posting: subscribe to
OnBeforePost...and raiseErrorif business rules don't pass. - Trigger an integration: subscribe to
OnAfterPost...and queue a job to call an external API.
Anti-patterns
Subscribing to dozens of OnBefore events to inject conditional behaviour. Long-running synchronous subscribers (move them to job queue entries). Subscribers that depend on the order other subscribers run in (they shouldn't). And subscribers that mutate the publisher's record after it's been written — almost always wrong.
Further reading
Related guides
- Business Central CI/CD with AL-GoHow AL-Go for GitHub turns an AL extension repo into a build-test-deploy pipeline — secrets, environments, and continuous delivery.
- The AL test frameworkWriting automated tests in AL — test codeunits, test runners, TestPage, mocking, test isolation, and CI with AL-Go.
- Writing your first AL extensionA first-walkthrough of building, publishing, and running a basic AL extension for Business Central — toolchain, project structure, and deployment.
- The Business Central API and OData servicesHow external systems talk to Business Central — the v2.0 REST API, OData web services, bound actions, and call limits.
- AL extension architectureHow AL extensions are structured in Business Central — objects, namespaces, app.json, dependencies, and the runtime model.
Browse every guide in Business Central or just AL & development.
Was this helpful?
Signals which guides land and which need work. No account, no comment box — corrections go through the contact page.
Spot something wrong or want a topic covered? Send a correction or a topic request — both are welcome.