An interesting and compelling technical feature (Events) was added to Dynamics NAV with the 2016 release and continues to be a focal point in Microsoft’s messaging to partners, ISVs, and customers with the recent 2017 release. Events provide the ability to customize NAV functionality and behavior without requiring customization of NAV's source code. We'll review the significance of that last sentence for the traditional NAV customer / environment at the end of this blog post.
If you have basic C/AL and NAV development experience you're no doubt familiar with functions. NAV Events are just functions where the function's "signature" includes a couple new properties identifying the function as an Event Publisher or Subscriber. The screen clips below show the properties used to configure a function as an Event Publisher or Subscriber.
Once a function has been configured as an Event Publisher, we can "raise" the event within an object simply by calling the function. Very similar if not identical in most ways to code many of us have written in the past. The next clip shows the new Publisher being "raised" within the OnRun trigger in a "Demo" Codeunit object.
That's nice but nothing happens when I run the Codeunit (or so it seems). I previously configured the Subscriber function to reference Publishing function. Lets see what happens when I add a simple C/AL MESSAGE to the Subscriber. Re-running the Codeunit now causes my new Message to display.
Success (sort of). I just wrote code that required two functions to show a simple MESSAGE dialog which could easily been displayed with a single (or no!) function call at all. How is this progress? Did you pick up on the fact that nowhere in the code have I explicitly called MyEventSubscriber()? NAV handled that for me automatically!
The example thus far has been overly simplistic; in the real world, the Subscriber function would not be located in the same object as the Publisher function. Additionally, it is entirely possible more than one Subscriber would have been configured and execute when a given event was "raised". Take a look at the following clips showing a new Codeunit (and new Subscriber function) I am adding. The new Subscriber also references the previously created Publisher in the original Codeunit object.
Re-run Codeunit 50000 and now not only do I get the original message but this one as well!
Let's build on the concepts introduced above and compare "the old way" of customizing NAV with "the new way" to pull this all together and really understand the significance of this new feature. Here's a simple "problem statement" I'll code in the old way and then again the new way: "Show a message when a Customer record is added to the database".
Old Way – modify base NAV object (Customer table) adding new custom functionality:
New Way – subscribe to Customer table OnAfterInsertEvent in a new custom object / function to modify base NAV functionality without customizing base NAV source code!
Awesome! I just created custom application behavior without customizing any base NAV objects!
Why does this matter / why should you care?
I've still ultimately added custom objects and code to the environment. How is the new way better than the old way? Many of you reading this have likely been frustrated with the effort / cost / duration associated with a past NAV upgrade. Handling the customizations in base NAV objects is a primary driver of complexity, cost, effort, and risk when attempting to upgrade a NAV environment. Those factors could be dramatically reduced if there were a way to provide the custom NAV application functionality you need in a way that did not also add "technical debt" (in the form of modified base NAV source code) to your NAV environment. Events are the way.
Keep an eye out in the coming weeks for additional related posts. I'll cover Events in greater technical detail, explore differences in how I'd code a couple "real world" modifications in an "event enabled" NAV version vs. "the old way", and finally discuss some strategy, ideas, and work I think users of pre-NAV 2016 versions should be considering today regardless of your current upgrade plans.