web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

NAV Events: the strange behaviour that I hate…

Stefano Demiliani Profile Picture Stefano Demiliani 37,166 Most Valuable Professional

Events in Microsoft Dynamics NAV (and in Dynamics 365 Business Central) are one of the best features of the platform ever. With events, you can now extend your business logic without modifying the original objects and events are the core for the new Extension model that we’ll use for Dynamics 365 Business Central.

However, there’s a little strange behaviour regarding events that personally I don’t like and that sometimes can be the cause of many problems in a business process. I want to show here what I mean with a quick example.

In my NAV environment I’ve created a simple table 50000 called Event Test with the following fields:

EventProblem_01.jpg

In this table, I’ve defined a Business event called MyEvent:

EventProblem_02.jpg

The event has this signature:

EventProblem_03.jpg

It receives in input a Code field and a Date field. The event is triggered in the table OnInsert trigger:

EventProblem_04.jpg

After that, I’ve created a codeunit (id = 50001) for handling this event. Here, I have a function called HandleEvent that is a Subscriber of my previously defined event:

EventProblem_05.jpg

The HandleEvent function code here only shows a message with some details:

EventProblem_06.jpg

Now I run my table and I insert a record. My business event is triggered correctly:

EventProblem_07

Now, the business requirements are changed and someone a day changes the Event signature on my table 50000. Now the MyEvent is defined as follows:

EventProblem_08.jpg

and in the table’s OnInsert the event it’s triggered as follows:

EventProblem_09.jpg

Save and compile the table, then try to compile the previously defined codeunit 50001. Magically, it compiles, no errors are triggered.

Now, execute the table 50000 and try to insert a record: the record is correctly inserted but the business event is not triggered:

EventProblem_10.jpg

This behaviour is quite strange, because 99% of the times no errors are triggeres, while I’ve found that sometimes an error at runtime is triggered that alerts you about the event change.

Obviously, this is a stupid example, but imagine a business process where this event passes values to a function used for modify data in NAV (if the event is triggered, data are modified otherwise no). If the event is changed and then it’s not triggered because in C/AL noone has modifyed the subscriber, my business process could give a wrong result.

Ok, NAV provides the Event Subscription view (from Development Environment, on the Tools menu, choose Debugger, and then choose Event Subscriptions) where you can find all Subscribers attached to a published event, but this is not enough.

Why, during compilation of objects, a compile error cannot be triggered? If in my example Codeunit 50001 will not compile, I’ll discover immediately the event signature change and I could act accordingly by modifying my event subscriber.

Hey NAV Team, any ideas?


This was originally posted here.

Comments

*This post is locked for comments