Every developer working with AL, probably, have been in a situation where there was the need to use an event. One of the main challenges of interacting with Microsoft D365 Business Central standard code if finding the event where the customization should fit. These events are often hard to find when coding, and there are basically two ways of finding an event:
- Open the standard object definition and go throughout the code searching for the event;
- Using the Web Client Event Recorder functionality.
In this ArquiTips we will show how to use the Event Recorder. In this case, the purpose of the Event Recorder usage is to find the events triggered when posting a Sales Invoice.
- Open Business Central Web Client and search for Event Recorder
- Open Event Recorder in a new page
This step is essential, otherwise the Event Recorder will not record any event.
- Start recording the events
Press action Start, in the Record Events action group, and do not close the Event Recorder page.
- Post the Sales Invoice and stop the Event Recorder
After posting the Sales Invoice, go back to the Event Recorder page and press the Stop action in the Record Events action group. A message with the number of recorded events should be shown.
- View the recorded events
A list with the recorded events should be presented. Since that are a lot of events that happened in the posting but are not related to posting, we can filter the list so show us, for instance, just the events that occur in the posting Codeunit.
- Subscribe the event
Having found the event to subscribe, the next step is to subscribe the event in AL. In Event Recorder, next to the Calling Method column, there is a Get AL Snippet action that will return a message with the Event Subscriber definition. Just copy the message content and paste it in your AL project.
Another way to subscribe to the event is to use the command AL: Find Event (Alt+Shift+E) in VS Code. Just type the name of the event to subscribe the event is automatically brought to our Codeunit.