Event-based architecture
With events, it's possible to connect to the core application without needing to modify the existing code. When an event occurs, you can react with your own code to these events. An event is a declaration of an occurrence of change. This declaration is done by an AL function, which is referred to as an event publisher.
The difference between an event publisher and a regular function is that an event publisher only has a signature, it does not run code. The signature of a function is only the name with its parameters and the return value type.
The three participants that are involved in events are:
The event
A publisher
A subscriber
Publisher
The object that contains the event publisher function is called the publisher. It declares and exposes the event in the application where people can subscribe on.
Subscriber
A subscriber listens for and handles a published event. It is also an AL function that subscribes to an event publisher function. This function includes the logic for handling the event.
When an event is raised, the subscriber function is called, and the code is run. This process enables partners to connect to the core application and intercept in certain core processes.
Reasons for events
Events separate the customized functionality from the application business logic, and you can intercept without having to modify the original code.
Because of the use of these events, changes to the original application code have a minimal impact on the customizations. As a result, the cost of code modifications and upgrades is lowered.
Implement events
To implement events, follow these steps:
Publish the event - Create and configure a function.
Raise the event - Add code that calls the event publisher function.
Subscribe to the event - Add one or more subscriber functions.
The three types of events are:
Business
Integration
Trigger
Business events
Business events are custom events that define a formal contract. This contract promises that the signature of this event does not change in future releases. It's published by solution ISVs, including Microsoft.
Integration events
Integration events are custom events that do not carry the same promise. They can change over time, which enables integration of other solutions without having the need to perform code modifications in the core application.
Trigger events
Trigger events are pre-defined events and raised by the system when it performs database table operations. When a record is deleted, inserted, modified, or renamed, a trigger is raised.
The trigger events are closely associated with the following table triggers:
OnDelete
OnInsert
OnModify
OnRename
OnValidate (for fields)
Each database operation has two trigger events with a fixed signature. These triggers have a before and an after trigger event.
OnBeforeInsert
OnAfterInsert
OnBeforeDelete
OnAfterDelete
OnBeforeModify
OnAfterModify
OnBeforeRename
OnAfterRename
OnBeforeValidate
OnAfterValidate