Dynamics 365 Business Central: using the Event Recorder for developing

When you are developing an extension for Dynamics 365 Business Central and you need to interact with the standard Microsoft’s code, one of the hardest problem is detecting which event you can subscribe to (as you already know, you cannot modify standard code in the D365BC SaaS platform but you can only attach to events raised by the platform).

For checking the published events and detect the event that suits your needs, you have essentially two ways:

  1. Opening C/SIDE in your local sandbox and checking standard Microsoft’s code from there
  2. Go-To Definition from AL code in Visual Studio code and inspecting the AL code
  3. Using the new Event Recorder feature

I don’t want to talk here about point 1: this is the old-style way but I’ve to admit that I often use it 😉

Point 2 is quite simple: create an event subscriber definition in Visual Studio Code, right click your object and select Go To Definition:

EventRecorder_07

You can now see the AL code for your object and then you can check the events:

EventRecorder_08.jpg

Obviously, to use this way you need to know the object to inspect (in this sample the Codeunit 80 Sales-Post).

Point 3 is useful when you don’t know the objects involved in a business process.

The Event Recorder feature was announced in the July Developer Preview for Dynamics 365 Business Central and it’s currently in preview. With this feature, you can register all the events raised when performing a certain action in Dynamics 365 Business Central and then detect what’s the best event for your needs.

To use this feature, you need to search for Event Recorder and then open the relative page. Here you have a Record Events menu with a Start and Stop button. Press Start to start the recording process:

EventRecorder_01.jpg

A confirmation dialog appears. Press Yes to start recording events:

EventRecorder_02

Now, open a new window in the browser and from this window start performing yor business process. In this example I’ve created a new Sales Order with a Sales Order Line.

P.S. It’s important to open a new window or you could have problems on logging the events (and it’s quite noisy to perform a N minutes business process and then discover that your events are not logged).

When you have finished the process, press the Stop button in the Event Recorder page. All the raised events are logged in the exact order they were called and you can see the event (name and type) and the object where the event is published:

EventRecorder_03

When you have detect your desired event, you can go to the GET AL SNIPPET column and click it:

EventRecorder_04

Dynamics 365 Business Central provides you a popup with the AL code for the Event Subscriber:

EventRecorder_05.jpg

You can paste this code and use it in your AL extension project in Visual Studio Code.

You can also directly open the Event Recorder page from Visual Studio Code by going to the command palette (CTRL+SHIFT+P) and select AL:Open Events Recorder:

EventRecorder_06.jpg

A little noisy thing: remember that the recorded events are not persisted, so if you close and reopen the Event Recorder page, the recorded events disappear.

This is a first step on helping a developer to work with standard events from Visual Studio Code and the D365BC platform without using C/SIDE. My suggestion is to try using this tool.

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.