What you need to know about NAV Events – Part 1

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.

What you need to know about NAV Events – Part 1

What you need to know about NAV Events – Part 1 2

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.
What you need to know about NAV Events – Part 1 3

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.
What you need to know about NAV Events – Part 1 4

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.

What you need to know about NAV Events – Part 1 5What you need to know about NAV Events – Part 1 6
Re-run Codeunit 50000 and now not only do I get the original message but this one as well!
What you need to know about NAV Events – Part 1 7
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:

What you need to know about NAV Events – Part 1 8

Results in:

What you need to know about NAV Events – Part 1 9

New Way – subscribe to Customer table OnAfterInsertEvent in a new custom object / function to modify base NAV functionality without customizing base NAV source code!
What you need to know about NAV Events – Part 1 10

What you need to know about NAV Events – Part 1 11
Results in:

What you need to know about NAV Events – Part 1 12
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.

 

5 Signs It's Time to Find a New Microsoft Dynamics NAV Partner Button

Innovia Consulting

Innovia Consulting

Innovia is a multiple-award-winning Microsoft Dynamics NAV and Business Central consulting firm known for delivering innovative Microsoft ERP systems while providing exceptional client-focused service. With four project teams and a dedicated support team, Innovia has the resources to handle all types of ERP projects.

Related Posts