Business Events - Custom Payload (IV)

Business Events: Custom Payload (IV)

As you know (I hope 😅), a few days ago we presented a session about Business Events for Developers at DynamicsCon. In this session, we were talking, among other things, about how we could customize the payload of the Business Events that we expose to the outside, to give them a different structure than the one that comes by default, and being able to reuse all the functionality that Dynamics F&O brings OOB.

Al finalizar la demo, tuvimos unos minutos de Q&A en directo, y uno de los asistentes (J.C.) hizo una consulta relacionada con la parte de los payloads personalizados: ¿Al descargar el esquema desde el catálogo de eventos de negocio, este refleja las modificaciones introducidas con este payload personalizado?. La respuesta, desgraciadamente, fue que no, pero me pareció una gran idea que no me había pasado por la cabeza, aparte de ser realmente útil si vas a consumir los eventos por ejemplo en Power Automate, así que me puse manos a la obra y este ha sido el resultado.

At the end of the demo, we had a few minutes of live Q&A, and one of the assistants (J.C.) made a question related to the part of custom payloads: When downloading the scheme from the business events catalog, does it reflect the modifications introduced with this custom payload?. The answer, unfortunately, was no, but it seemed like a great idea that had not crossed my mind, apart from being really useful if you are going to consume the events for example in Power Automate, so I got down to work and this has been the result.

The first thing I did was check the possibility of extending the functionality of the “Download schema” button to try to modify its behavior, but it is not possible to go that way, so, finally, I decided to duplicate this button, and play with the visible property of both buttons, the standard and the duplicated, depending on the JATCustomEvent field that we added to the events catalog (BusinessEventsTable) to identify those events that will work with the custom payload.

Once the button is duplicated, we will control in the active method the visible property of the two buttons, the standard and the duplicate, basing its value on the JATCustomEvent field of the event catalog (BusinessEventsTable), which was created to identify those events that should use custom payload.

Finally, we add a new method to the extension of the BusinessEventsCatalogHelper class. This method will be a “duplicate” of the getJSONSchema method that generates this schema in a standard way, with the necessary modifications to respect our structure.

And this method will be executed from the new button that we have created, downloading the value returned by it in a text file, just as the standard does.

And in this simple way we manage to add a little more functionality, adding great value to our development.

From here I want to thank the user J.C. (Sorry, but I don’t know your name 🤷‍♂️) for giving me the idea during the event to improve the product, and as always, the complete solution is available in the GitHub repository.

Greetings!


2 comments / Add your comment below

  1. Followed this but I have run into an issue. I am unable to deserialize the Business event contract when it contains a list. Maybe you can assist me with this.

    1. Hi Kenny, thanks for comment :).
      Sure, you have to decorate the parm method that returns the list with the DataCollectionAttribute attribute, so you will let the deserializer know that this is a collection (list) and the type of the elements that contains.

      Example, if you have a list of MyClass elements, you have to decorate it as following:

      DataCollectionAttribute(Types::Class, classStr(MyClass))

      Also, don’t forget the DataMemberAttribute attribute as well.

      Hope it hepls you, best regards!

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