Making Upgrades in Microsoft Dynamics NAV 2016 Easier:
How to Use the Event Subscriber Functions to Help Eliminate the Need to Modify Base Objects
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.
Figure 1. Viewing Table 18 Customer in the Table Designer.
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”:
Figure 3. The Object Designer.
Create a new function called “OnValidateAddress”:
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:
Figure 5. Properties of the OnValidateAddress function.
Finally, enter the C/AL code that will validate the Address field:
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:
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:
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.