Study guide
8.2 Events, Publishers, Subscribers & Event Isolation
Microsoft Dynamics 365 Business Central Developer MB-820
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: Business Central Architecture & Platform Foundation
1.1 Business Central Architecture & Extensions Model 1.2 Customization Lifecycle: Cloud (SaaS) vs. On-Premises 1.3 Base Application, System Application & AppSource
2 Chapter 2: Development Environment & Configuration
2.1: Development Environment Setup: VS Code, AL: Go! Projects & Sandboxes 2.2: AL Configuration Files: app.json & launch.json Parameters 2.3: Multi-Root Workspaces & Project Dependencies
3 Chapter 3: Extension Lifecycle: Debugging, Deployment, Multilanguage & Maintenance
3.1 Debugging & Snapshot Debugging in Visual Studio Code 3.2 Extension Deployment & Schema Synchronization Modes 3.3 Multilanguage Development with XLIFF & Translation Files 3.4 Extension Maintenance, Deprecation & Breaking Changes
4 Chapter 4: Tables, Table Extensions & Data Modeling
4.1: Building Tables, Fields, Keys & Data Types 4.2: Table Extensions & Table Modifications 4.3: FlowFields, FlowFilters & Table Relations 4.4: Enums, Enum Extensions & Extensible Types
5 Chapter 5: Pages, Page Extensions & Role Centers
5.1: Page Types, Anatomy & Control Structure 5.2: Building Card, List & Document Pages 5.3: Page Extensions & Page Customizations 5.4: Role Centers, Headlines & Cue Data Modeling
6 Chapter 6: Reports & Document Generation
6.1 Report Architecture, DataItems & Dataset Design 6.2 Report Layouts: RDLC, Word, Excel & Multilanguage 6.3 Document Reports & Request Page Programming 6.4 Processing-Only Reports & Report Substitutions
7 Chapter 7: XMLports & Data Exchange
7.1 XMLport Architecture, Formats & Properties 7.2 XMLport Node Hierarchy, Triggers & Stream Manipulation
8 Chapter 8: Codeunits, Events, Triggers & Interfaces
8.1 Codeunit Types, Execution & SingleInstance Codeunits 8.2 Events, Publishers, Subscribers & Event Isolation 8.3 Interfaces, Polymorphism & Dynamic Codeunit Invocation 8.4 Installation & Upgrade Codeunits, Data Transfer & Archive
9 Chapter 9: Entitlements, Permissions & Queries
9.1 Permission Sets & Permission Set Extensions 9.2 Inherent Permissions, Inherent Entitlements & Security Scoping 9.3 Query Objects: Joins, Aggregation & Query as Report Data Source
10 Chapter 10: UI Customization, User Assistance & Onboarding
10.1 Profile Objects & Custom Page Views in AL 10.2 User Assistance: ToolTips, Teaching Tips & In-App Tours 10.3 Assisted Setup, Guided Experience & Onboarding Checklists
11 Chapter 11: Business Central Design Patterns & Data Process Model
11.1 Functional Table Types: Master Data, Supplemental & Setup Patterns 11.2 Document Standards: Header, Line, History & Journal Architectures 11.3 Data Process Model & Posting Routine Architecture
12 Chapter 12: AL Language Fundamentals, Data Types & Variables
12.1 AL Syntax, Variable Scope, Primitive & Complex Data Types 12.2 Expressions, Control Flow Statements & Built-in Functions 12.3 Access Modifiers (Public, Internal, Local) & Code Scoping
13 Chapter 13: Data Manipulation, Streams & Error Handling
13.1 Record Operations: Get, FindSet, ModifyAll & Filter Functions 13.2 Streams, File Management & TempBlob 13.3 Error Handling: ErrorInfo, TryFunctions & Collectible Errors
14 Chapter 14: Testing, Test Toolkit & Automation
14.1 Testing Architecture & the Test Toolkit 14.2 Authoring Test Codeunits & UI Handler Functions
15 Chapter 15: Telemetry, Performance Optimization & Analyzers
15.1 Telemetry Configuration & Azure Application Insights 15.2 Custom Telemetry Signals with Session.LogMessage & KQL 15.3 Performance Profiler, SetLoadFields & Query Optimization 15.4 AL Analyzers: CodeCop, AppSourceCop, UICop & PTECop
16 Chapter 16: REST Web Services & JSON in AL
16.1 HttpClient, HttpRequestMessage & REST API Consumption 16.2 JSON Processing: JsonObject, JsonArray, JsonValue & JsonToken
17 Chapter 17: API Pages, OData, Read Scale-Out & OAuth
17.1 API Pages (PageType=API), OData Web Services & REST Endpoints 17.2 Bound and Unbound OData Actions with [ServiceEnabled] 17.3 Read Scale-Out Architecture & DataAccessIntent Configuration 17.4 Microsoft Entra ID App Registrations & OAuth 2.0 Integration
8.2 Events, Publishers, Subscribers & Event Isolation
Key Takeaways Explain This Topic AI
Event-driven architecture in AL decouples custom extension logic from the core Base Application, ensuring upgrade resilience without source code modification.
IntegrationEvent is the primary extension point for developers, whereas BusinessEvent represents an immutable public contract with long-term signature stability.
Event subscribers are declared using the [EventSubscriber] attribute, specifying the publisher object type, object ID, event name, element name, and licensing/permission flags.
Event isolation (Isolated = true) ensures that failing subscribers execute in isolated transaction boundaries, preventing errors from rolling back peer subscribers.
The IsHandled design pattern allows subscribers to intercept standard business routines and conditionally suppress default base application calculations or posting routines.
Last updated: August 2026
8.2 Events, Publishers, Subscribers & Event Isolation
The event-driven architecture is the cornerstone of modern Business Central extensibility. Prior to the AL extension model, customizations involved modifying base C/AL source code directly, creating complex merge conflicts during cumulative updates. In AL, developers cannot alter standard source files; instead, the platform exposes thousands of publisher events throughout core tables, pages, reports, and codeunits. Developers write subscriber procedures that listen for these events, injecting custom logic seamlessly without altering base code.
1. Event Publisher Types & Attributes
An event publisher is a procedure declaration decorated with an event attribute. Publisher procedures contain no AL body code (no begin...end block or variable definitions) and are invoked directly from operational code using their procedure name. codeunit 50110 "Custom Order Processor"
- {
- // 1. Integration Event Publisher
- [IntegrationEvent(true, false)]
- procedure OnBeforeProcessCustomOrder(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)
- begin
- end;
- // 2. Business Event Publisher (Formal Contract)
- [BusinessEvent(false)]
- procedure OnCustomerCreditLimitExceeded(CustomerNo: Code[20]; OverdueBalance: Decimal)
- begin
- end;
- // 3. Internal Event Publisher (Module Scope)
- [InternalEvent(false)]
- procedure OnInternalValidationCompleted(DocumentNo: Code[20])
- begin
- end;
- // 4. Isolated Event Publisher
- [IntegrationEvent(false, false, true)]
- procedure OnAfterBroadcastNotification(NotificationId: Guid; MessageText: Text[250])
- begin
- end;
- procedure Execute(var SalesHeader: Record "Sales Header")
- var
- IsHandled: Boolean;
- begin
- // Raising the integration event
- OnBeforeProcessCustomOrder(SalesHeader, IsHandled);
- if IsHandled then
- exit;
- // Standard processing continues if not handled
- PerformStandardProcessing(SalesHeader);
- end;
- local procedure PerformStandardProcessing(var SalesHeader: Record "Sales Header")
- begin
- // Base processing logic
- end;
- }
- Comparing Event Publisher Attributes
Attribute Scope / Visibility Purpose & Stability Arguments
[IntegrationEvent] Global (all extensions). General-purpose extension point across tables, pages, and codeunits. Can evolve across major releases. IncludeSender: Boolean , GlobalVarAccess: Boolean , Isolated: Boolean
[BusinessEvent] Global (all extensions). Formal business contract (e.g., invoice posted, payment released). Guarantees permanent signature stability. IncludeSender: Boolean , Isolated: Boolean
[InternalEvent] Module-internal only. Internal communication within the same extension package. Not visible to external apps unless granted via internalsVisibleTo . IncludeSender: Boolean , Isolated: Boolean
Publisher Arguments Explained
IncludeSender: Boolean : When set to true , the publisher signature implicitly exposes a sender parameter of type Codeunit "PublisherName" or Record "TableName" to subscribers, granting access to the publishing instance's public methods.
GlobalVarAccess: Boolean : Legacy setting allowing subscribers to read and modify global variables of the publishing object. Marked obsolete in modern AL development and restricted to false in cloud-compliant apps.
Isolated: Boolean : When set to true , the platform executes each subscriber in its own isolated transaction boundary. If one subscriber encounters an unhandled runtime error, the engine catches the error, rolls back only that subscriber's changes, logs the error, and proceeds to execute all remaining subscribers without failing the overall transaction.
Loading diagram... Event Subscriber Invocation Pipeline & IsHandled Design Pattern
2. Event Subscribers in AL
An event subscriber is a procedure decorated with the [EventSubscriber] attribute that listens for a specific event raised by an object in the system. codeunit 50115 "Sales Post Subscriber"
- {
- EventSubscriberInstance = StaticAutomatic; // Default behavior
- [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', true, true)]
- local procedure HandleOnAfterPostSalesDoc(
- var SalesHeader: Record "Sales Header";
- var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line";
- SalesShptHdrNo: Code[20];
- SalesInvHdrNo: Code[20];
- SalesCrMemoHdrNo: Code[20];
- InvHdrBuffer: Record "Invoice Post. Buffer")
- begin
- if SalesInvHdrNo <> '' then
- SendCustomInvoiceEmailNotification(SalesInvHdrNo);
- end;
- local procedure SendCustomInvoiceEmailNotification(InvoiceNo: Code[20])
- begin
- // Custom notification workflow
- end;
- }
[EventSubscriber] Parameter Breakdown [EventSubscriber(ObjectType, ObjectId, EventName, ElementName, SkipOnMissingLicense, SkipOnMissingPermission)]
ObjectType : The AL object type publishing the event ( ObjectType::Table , ObjectType::Page , ObjectType::Codeunit , ObjectType::Report , ObjectType::XMLport ).
ObjectId : The symbolic object identifier (e.g., Codeunit::"Sales-Post" or Database::Customer ).
EventName : String literal naming the publisher procedure (e.g., 'OnAfterPostSalesDoc' ).
ElementName : Target field name or control name when subscribing to table field triggers ( OnAfterValidate ) or page control triggers. Empty string '' for object-level events.
SkipOnMissingLicense : If true , the runtime ignores this subscriber silently if the tenant license does not cover the publishing object, preventing runtime licensing crashes.
SkipOnMissingPermission : If true , the subscriber is skipped without error if the current user lacks read/write permissions to the publishing object or its underlying tables.
Static vs. Manual Event Subscribers
By default, codeunits have EventSubscriberInstance = StaticAutomatic , meaning all subscribers inside the codeunit are bound automatically upon tenant startup. However, developers can configure manual binding:
EventSubscriberInstance = Manual : The codeunit's subscribers are inactive by default.
BindSubscription(CodeunitInstance) : Dynamically activates the subscribers on the specific codeunit instance at runtime.
UnbindSubscription(CodeunitInstance) : Deactivates the subscribers.
Use Cases : Critical for automated testing (binding mock subscribers during specific test functions) and transient workflow interception.
- 3. Standard Platform Trigger Events & The IsHandled Pattern
- Built-in Table and Page Trigger Events
Every table and page in Business Central emits standard platform trigger events automatically without requiring manual publisher code:
Table Trigger Events : OnBeforeInsertEvent , OnAfterInsertEvent , OnBeforeModifyEvent , OnAfterModifyEvent , OnBeforeDeleteEvent , OnAfterDeleteEvent , OnBeforeRenameEvent , OnAfterRenameEvent , OnBeforeValidateEvent , OnAfterValidateEvent .
Trigger Event Parameters : Built-in table events provide var Rec: Record TableName , var xRec: Record TableName , and RunTrigger: Boolean .
Page Trigger Events : OnBeforeOpenPageEvent , OnAfterOpenPageEvent , OnClosePageEvent , OnQueryClosePageEvent , OnBeforeValidateEvent , OnAfterValidateEvent .
The IsHandled Design Pattern
The IsHandled pattern allows an extension to completely replace standard Business Central calculations, document routing, or posting routines without modifying core objects. // 1. Core Base Application Publisher Pattern
- procedure CalculateTax(var SalesLine: Record "Sales Line")
- var
- IsHandled: Boolean;
- begin
- IsHandled := false;
- OnBeforeCalculateTax(SalesLine, IsHandled);
- if IsHandled then
- exit;
- // Standard internal tax engine executes here
- SalesLine."VAT %" := 20.0;
- SalesLine."Amount Including VAT" := SalesLine.Amount * 1.2;
- end;
- // 2. Extension Subscriber Overriding Standard Behavior
- [EventSubscriber(ObjectType::Codeunit, Codeunit::"Tax Management", 'OnBeforeCalculateTax', '', false, false)]
- local procedure OverrideWithThirdPartyTaxEngine(var SalesLine: Record "Sales Line"; var IsHandled: Boolean)
- var
- ExternalTaxService: Codeunit "External Tax Service";
- begin
- if IsHandled then
- exit; // Another subscriber already handled this operation
- SalesLine."VAT %" := ExternalTaxService.GetCalculatedRate(SalesLine."No.", SalesLine."Tax Group Code");
- SalesLine."Amount Including VAT" := SalesLine.Amount * (1 + (SalesLine."VAT %" / 100));
- IsHandled := true; // Suppresses standard base tax calculation
- end;
Exam Watchout — Execution Order Non-Determinism: If multiple extensions subscribe to the exact same event publisher, the execution order of the subscribers is non-deterministic . Always check if IsHandled then exit; at the start of your subscriber procedure to ensure you do not overwrite another extension's handling inadvertently.