Skip to content

Michael Heydasch's picture

Making Upgrades in Microsoft Dynamics NAV 2016 Easier:
How to Use the Event Subscriber Functions to Help Eliminate the Need to Modify Base Objects

ArcherPoint’s technical staff pose questions, find answers, and share new discorveries about Microsoft Dynamics NAV

Formerly codenamed “Corfu,” Microsoft Dynamics NAV 2016 – or version number 9.00—has just been released. There are many exciting new features, but my first blog focuses on the Event Subscriber functions, because they can help make upgrading to NAV 2016 easier.

What are Event Subscriber functions?

From the NAV Help documentation:

Event subscribers determine what actions to take in response to an event that has been raised. An Event Subscriber is a C/AL function that subscribes to, or listens for, a specific event that is declared by an event publisher function. The Event Subscriber includes code that defines the business logic to handle the event. When the published event is raised, the Event Subscriber is called and its code is run.

One way to describe an Event Subscriber function is to illustrate a business case scenario:


A business requirement has arisen to eliminate entry of the percent symbol (%) in the Address field of the Customer table.

Solution in previous versions

The way to address this business requirement in previous versions was to add code to the OnValidate trigger of the Address field of Table 18, Customer.

Viewing Table 18 Customer in the Table Designer.

Figure 1. Viewing Table 18 Customer in the Table Designer.

Viewing Table 18 Customer in the C/AL Editor.

Figure 2. Viewing Table 18 Customer in the C/AL Editor.

Why this is not the preferred method: A modification to a base NAV object means the customization will have to be carried into future versions of NAV. Obviously, this will increase the cost of the upgrade because of the time required to merge the customizations into the new base objects. The goal is to minimize, if not eliminate, customizations to base NAV objects.

Solution in NAV 2016

Objects numbered 50000 to 99999, while they must be purchased for use by the client, are in a custom range designated for client use. They can be migrated into NAV 2016 without being merged, and they can be tested to ensure the prior code is compatible with the new version.

Design a new codeunit numbered 50000 and named “CustFcns”:

The Object Designer.

Figure 3. The Object Designer.

Create a new function called “OnValidateAddress”:

The C/AL Globals window.

Figure 4. The C/AL Globals window.

Select Properties on the new function … change Event to Subscriber, enter T18 on EventPublisherObject, select OnBeforeValidateEvent for EventFunction, and select the field Address for OnValidateEventField:

Properties of the OnValidateAddress function.

Figure 5. Properties of the OnValidateAddress function.

Finally, enter the C/AL code that will validate the Address field:

Viewing Codeunit 50000 CustFcns in the C/AL Editor.

Figure 6. Viewing Codeunit 50000 CustFcns in the C/AL Editor.

Save the object and close the Codeunit Designer. Now, notice Table 18 Customer is untouched:

The Object Designer.

Figure 7. The Object Designer.

Yet, if we run the Windows client and attempt to enter the symbol (%) in the Address field, we get an error:

Viewing Page 21 Customer Card in the NAV Windows Client.

Figure 8. Viewing Page 21 Customer Card in the NAV Windows Client.

We achieved our modification without touching NAV base objects! This is possible through the Trigger Events built into the base product.

The developer should be cognizant of the fact that there may be more than one function subscribed to a particular event. Microsoft refers to this as a “value-chain,” which basically means that this function may be the first, fifth, or tenth subscription function to be called as part of the event. The developer should take this into consideration and code accordingly.

If you have any questions about the Event Subscriber function or about NAV 2016, please contact the experts at ArcherPoint. Also, stay tuned for more blogs about NAV 2016.

If you enjoyed this blog, you might like to check out our collection of Development Blogs, as well as our "How To" blogs for practical advice on using Microsoft Dynamics NAV.

Blog Tags: 


AntidotE's picture



Is it possible to track these event subscribers to be able to add/change code in proper place?

What if some addon (which I do not have acces to) adds subscriber and does some change.

And my subscriber, for example, requires this change to be already executed to be able to do what it is designed for. Can I rule the sequence of subscribers?

Michael Heydasch's picture


Thanks for your comment!

Regarding your first question: Table 2000000140 Event Subscription should contain the records you need.

Regarding your second question: The NAV Team has stated there is absolutely no control over the sequence in which the event subscribers are called, so you must take care when coding your application. Here is a link for more information on subscribing to events in NAV. Think about alternative ways to code … you might, for example, write a record to a log table that would be processed by the NAS later, after the entire event subscriber value chain has executed.

Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Join us on Google+ Watch us on YouTube