Skip to main content

MSDYN365BC - Futuristic CAL Development - What If No Event Found?

Hi Readers,


Last article we Understand what is Integration Events.
As promised in this post we will understand if you don't find an event because you are not in Latest Version of NAV/Business Central or you are in a version which does not support Events (Pre-NAV 2016).

If you are new to this series then Please Refer Table of Index.

With this article, We will understand about HOOKS and Use Hooks for development.

This will help Developers to develop with keeping in mind about future and all code can be easily transported to future when your customer plan to Upgrade. Let's discuss that in details.



What we Need?
We always should have one Microsoft Standard Database installed on our local machine right now that is Microsoft Dynamics Business Central on-Prem Cumulative Update 03.

Why we need that?
As discussed in the Last article Microsoft keeps on and will keep on adding Integration Events in future. If we have the latest cumulative update of Business Central installed we will know which all events are available in future for our custom Code.

What is a Hook?
In programming, a hook is a place and usually an interface provided in a packaged code that allows a programmer to insert customized programming. For example, a programmer might want to provide code that analyzed how often a particular logic path was taken within a program.

Why use Hook?
As a partner, adding new code to NAV means interfering with code shipped by Microsoft. Minimize your footprint of changes in Microsoft code, so that, when a new NAV version is shipped, you avoid conflicts and upgrade impact. The core NAV code is the "danger zone"  - the less you touch it, the happier your upgrade will be.

Read More About Design Pattern
Read More About Hook Pattern


Hook Example - 
Consider the same example but our customer is using 2009 (which they should not use now 😃).

We want to copy Expense Code from G/L Account Table to Purchase Line When No. Get validated in Purchase Line table.

Let's Create a New Codeunit which will store all Hooks for this customization, as shown below.
Add a new function which is similar to Publisher in future. (Look in Latest CU).
Add parameters as available in Future Publisher. (Look in Latest CU).
Add Custom Code that we want to Execute in Base Objects.



Now as its not a Publisher in our customer database, we will have to write one line of custom code in the Base Objects that invokes this Hook as shown below.


In this example, we just wanted to add one line of code so it may seem like a bad idea but think of an example where you as developer write multiple lines of code in base objects. This will become a Boon for you in the future.

I hope you would have got the Idea about HOOKS and how to use them.

If you have any question, please add that as the comment to the article.

Next article, we will continue with our customer requirements.

Stay Tuned for More!!

Regards,
Saurav Dhyani

Comments

  1. Thanks, Saurav. I just want to make sure I understand this properly. Are you saying that when using hooks we are in fact modifying base NAV objects? Up until now I thought this was going to be absolutely prohibited. If so, what happens when Microsoft upgrades the object in a future CU? Wouldn't our hook be lost? Does this mean we have to manage our hooks and make sure they are re-established during each CU?

    ReplyDelete
    Replies
    1. @Justin - SO you will only use HOOKS till you are not using the latest version of NAV / Business central. If you plan to use HOOKS then you will have to maintain (merge) them during upgrade or cumulative update.

      I am suggesting hooks so that footprint of custom code in base objects (even in older versions) is less and these hooks will be replaced to Subscribers during upgrades to latest version. Once you are there lets say in Business central on Prem then NO HOOKS only SUBSCRIBERS.

      HOOKS Is for PRE-BUSINESS CENTRAL if you dont find appropriate event and you already checked that event exist in future.

      Hope it make sense. Let me know if any doubts.

      Delete
    2. Got it. Thanks for the clarification.

      Delete

Post a Comment

Popular posts from this blog

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing -