Events enable you to separate customized functionality from the application business logic.
By using events in the application where customizations are typically made, you can lower the cost of code modifications and upgrades to the original application.
Events can be used for different purposes, such as generating notifications when certain behaviour occurs or the state of an entity changes, distributing information, and integrating with external systems and applications.
How Events Work
There are three major participants involved in events: the event, a publisher and a subscriber.
An event is the declaration of the occurrence or change in the application. An event is declared by a C/AL function, which is referred to as an event publisher function. An event publisher function is comprised of a signature only and does not execute any code.
A publisher is the object that contains event publisher function that declares the event. The publisher exposes an event in the application to subscribers, essentially providing them with a hook-up point in the application. An event is raised by adding logic to the application that calls into the publisher to invoke the event (the event publisher function). There are three different event types: business, integration, and trigger events.
Business and integration type events must be explicitly declared and published, which means that you must create event publisher functions and add them to objects manually. On the other hand, trigger events, which occur on table and page operations, are published and raised implicitly by the Microsoft Dynamics NAV runtime. Therefore, no coding is required to publish them.
A subscriber listens for and handles a published event. A subscriber is a C/AL function that subscribes to a specific event publisher function and includes the logic for handling the event. When an event is raised, the subscriber function is a called and it code is run.
How to Implement Events
Implementing events in Microsoft Dynamics NAV consists of the following tasks:
- Publish the event. For business and integration events, create and configure a function in an application object to be an event publisher function.
- Raise the event. Add code that calls the event publisher function..
- Subscribe to the event. At the consumer end, add one or more subscriber functions that subscribe to published events when they are raised.
Will come up with how to practically use it in my upcoming posts.
[…] Recall from my earlier post for description of Events – Events in C/AL Navision 2016 […]
ReplyDelete[…] Recall from my earlier post for description of Events – Events in C/AL Navision 2016 […]
ReplyDelete