Events in Business Central - When to use events - types of events in business central - implementing event in business central
Using events, you may program the app to respond in many ways to user activity. Separating user-defined features from the business logic of an application is made possible through the use of events.
You can reduce the price of code updates and upgrades by making use of events in the application at the points where customizations are commonly made.
- Customized functionality code can be updated independently of the base app.
- It is possible to make modifications to the original program code with little to no effect on the customizations.
Use of Events
- Sending alerts when a predefined event occurs or the state of an entity changes
- Sharing data with other systems
- Connecting with third-party programs.
Types of Events
- BusinessEvent - Describes how to post events of a business-type.
- IntegrationEvent - Describes how to broadcast internal events.
- InternalEvent - Describes the procedure to use as an internal event publisher
- Global - System events with a predetermined global scope.
- Trigger - Trigger events are published by runtime.
Three Major Participants in Events
- Announcement of the occurrence or modification to the application
- An event publisher function, which is declared via an AL method.
- The event publisher method merely has a signature and doesn't run any code.
- A publisher is an object that uses the event publisher function to define an event.
- The publisher makes an application event available to the subscribers, giving the latter a point of entry into the application.
- While it may be tempting to think otherwise, publishing an event does nothing more than make it accessible by subscription.
- Subscribers can only react once the event has been triggered.
- Developers must add code (the event publisher function) to their apps that interact with publishers in order to make an event happen.
- Event publisher functions must be developed and these capabilities must be manually added to objects in order for events of the business and integration kinds to be explicitly published and raised.
- Trigger events, on the other hand, happen on table and page activities and are implicitly published and raised by the system during runtime. Thus, they can be released without the need for any coding.
- An event may be publicised, after which a subscriber may hear it and take appropriate action.
- An event handler (or subscriber) is an AL method that has subscribed to a certain event publisher method.
- Every time an event is created, the subscriber method's code is run.
- A subscriber allows third-party developers to integrate with the heart of an app without making custom alterations to the source code.
- Event subscribers can be used by any Dynamics 365 solution vendor, including Microsoft.
- A single event publisher method can have numerous subscribers. A publisher, however, is in the dark as to how many people are actually subscribing.
- Both publishers and subscribers can work from various portions of the app.
How to implement an event
Publish the event
- For business and integration events, it is advised to identify a specific method in an application object as an event publisher method.
- Trigger events are published by the system automatically, so this step is unnecessary.
Raise the Event
- Incorporate a call to the event publisher mechanism.
- Trigger events are automatically raised by the system, therefore this step is unnecessary.
Subscribe to the event
- Create a consumer-side subscriber method or methods that react to published events.
Save all the above codes as a single program.
Launch the customer card page.