NAV2016 | Events, implementing Loose Coupling in ERP

With the release of NAV2016 we get new possibilities for making changes to the product without raw source code modification.

This is called “events” and the concept is “stolen” from DotNET.

How does it work?

Traditionally if we want to execute extra functionality in NAV we simply make a change to the source code.

This is referred to as raw source code modification and is the root cause for the many hours NAV developers spend comparing and merging code. To simplify upgradability Microsoft now offers us to subscribe to events in the system. There are three types of events:

  • Table Triggers
  • Page Triggers
  • “Manual” event Publishers

The Table and Page triggers are relatively straight forward. Before and After the typical triggers such as OnInsert and OnValidate you can subscribe.


The manual raising of events is more interesting and is what this post is about. Most of the business logic of Dynamics NAV is in Codeunits. Large modules such as Sales Post, Reservation Engine Mgt. or Gen. Jnl.-Post Line. What if I want to trigger my code from there.

This is done using Integration or Business events that Microsoft implements in the product. Currently there are 128 of them. You can easily find them using the script from Waldo’s blog.


Event Execution

So when and how are these events executed? This is an interesting question since we can have multiple subscribers to one event.


In this screenshot we have 4 codeunits. Codeunit 50002 has an Integration event Foo that is raised in the OnRun trigger, then we have Codeunit 50000, 50004 and 50005, with subscribers. If you execute this you will find that EE comes first, then DD, CC, BB and AA. So it executes on object ID. This however is not guaranteed. Microsoft might change that in the future.

Service Level Agreements

What does that mean for the SLA that partners have with customers? My guess is that all partners will change their SLA to exclude any code that is triggered using events, or at best have a list of software that they trust to be save to use in combination with their software.

More Examples

Let’s take an example to be a little bit more extreme. Let’s go to back the post about treating a table as a class and have methods that call into codeunits. What if we implement loose coupling there.

In this screenshot I have implemented a method on the Sales Header table PostDocument and changed codeunit 81 to subscribe.


This is an example of loose coupling in NAV2016. But is it good? What if I add another subscriber? How would I know what code it executes.


With Partner Ready Software we implement Facades for this and Facades have similar challenges. In my next blog posts I will elaborate more on this and how to solve challenges we have when we implement loose coupling in NAV and prevent developers subscribing to events they should not subscribe too.

Hooks vs. Events

Another challenge will be deciding when to use events and when to keep on using hooks. I will also write a post about this.


1 Comment

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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