Business Events: Custom payload (II)

In the previous post we were talking about a solution that would allow us to customize the content and structure of the payload that is sent through Business Events drastically, so that we are able to adapt to a JSON format different from the standard of #MSDyn365FO, all this while still using the full power of this framework. Now, let’s move on to see in more detail the steps taken to reach this solution.

As we mentioned in the last post, we will divide this solution into two different parts:

  • Identify the events that must comply with the new format.
  • Modify the payload to send abroad.

In this specific article, we will talk about the technical aspects and the steps carried out to be able to fulfill the first point.

Identify events in the event catalog

In order to correctly identify which events must comply with the specific format, we have decided to “mark” them within the event catalog.

When we launch the functionality that is responsible for generating (or regenerating) the business event catalog, the system goes through all the classes that are decorated with the BusinessEventsAttribute attribute and generates a record in the event catalog (BusinessEventsTable) for each of the classes obtained (events).

The decision that has been taken to identify those business events that meet these new conditions was none other than to imitate the standard functionality, for this reason, a new attribute was generated that will be responsible for decorating these specific events, indicating the specific type of event (data requested in the new format), so that, when generating or regenerating this event catalog, we could obtain all the classes decorated with the new attribute and mark them somehow within the event catalog.

In order to meet this objective, the following steps were carried out.

1. Add 2 new fields to the BusinessEventsTable table.

To do this, we create the extension of the BusinessEventsTable.JATCustomEvent table, and add the fields:

  • JATCustomEvent: NoYes enum that will indicate whether or not that business event belongs to our catalog of custom events.
  • JATEventType: String that will store the specific event type.

2. Create new attribute to decorate custom business events.

To generate the new attribute, you basically have to create a class that inherits from the SysAttribute. Besides, we add a private property to be able to indicate in the attribute itself (through the new method) the type of event in question, and a method that will allow obtaining the associated value later.

3. Decorate our business event with the new attribute.

As you can see, apart from decorating our business event with the BusinessEventsAttribute attribute, we add the attribute that we have created, indicating by parameters the type of event, a value that will be added later to the payload.

(If you need more details about how to create new business events, you can get more information in this post).

4. Mark the events as “custom” within the event catalog.

For this last step, we are going to use the BusinessEventsCatalogHelper class, since it is in charge of going through the different business events of the system and creating as many records in the BusinessEventsTable table as business events there are in the system. Specifically, we are going to extend the addCodeBusinessEvents method, which is in charge of carrying out this management, adding at the end (after the next) the code necessary to update our events.

What we do in this method is to get all the events (classes) that are decorated with the attribute that we created in step number 2 and update the corresponding record of the BusinessEventsTable table so that it will be marked with the value of the JATCustomEvent field to “Yes” and will have the value of the event type assigned in the JATEventType field.

With these modifications we would already fulfill the objective of this article, to identify business events so that, as we will see in the next post, we are able to modify the structure of the message sent only for those events that we need.

PS: This code will be executed every time someone launches the action from the button Rebuild business events catalog or every time a database synchronization is performed.


1 comment / Add your comment below

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información. ACEPTAR

Aviso de cookies