#019 DISCOVERABILITY OF EVENTS

Skip to content

#019 DISCOVERABILITY OF EVENTS

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:

  1. Open the standard object definition and go throughout the code searching for the event;
  2. 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.

 

  1. Open Business Central Web Client and search for Event Recorder

Open Business Central Web Client and search for Event Recorder

  1. Open Event Recorder in a new page

This step is essential, otherwise the Event Recorder will not record any event.

Open Event Recorder in a new page

  1. Start recording the events

Press action Start, in the Record Events action group, and do not close the Event Recorder page.

Start recording the events

  1. 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.

Post the Sales Invoice and stop the Event Recorder

  1. 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.

View the recorded events

  1. 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.

Subscribe the event

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.

Another way to subscribe to the event is to use the command AL