Skip to main content

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

Hi Readers,

Last article we Understand what are Trigger Events.

As promised in this post we will understand if you are doing development in Pre-NAV 2016 Database.

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 the future and all code can be easily transported to the future when your customer plan to Upgrade. Let's discuss that in details.



What is 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.

What we Need?
We should know which Trigger (Tables & Pages) Events are supported in the Future. With that in mind, we will be writing code in the right approach and futuristic way.

Why we need that?
If you think that what we discussed in this article will be an overhead for the future you should not do that. I think there are advantage and disadvantages of using HOOKS for Table and Page Trigger Events but you as Developer can decide what suits you best.

If you use HOOKS for Page and Table Trigger Events then additional work will be removing those HOOKS and mapping it the right event. If you don't use HOOKS you will have to write all custom code outside during upgrade to new Version.

Why use Hook - Why I Suggest?
Yes, there will be an overhead in future to update HOOKS to Event Subscribers but below are benefits that I think will happen if you use HOOKS for Pre-NAV 2016 Database -

  • If you use HOOKS you will make sure that your right code in either OnBefore and OnAfter.
  • You will make sure that you will never write code in the middle of Table field, Table Trigger, Page Field and Page Triggers.
  • You will use HOOKS with and place all HOOK Code in multiple codeunit (related to 1 Functionality) which will help in future to segregate Extensions.
  • Using HOOKS will save cost and time in the future when you plan to Detangle the customizations in logical Extension.


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

We want to check and show an Error Message if Expense code selected by a user in G/L Account in Blocked.

What would we do as a current developer?



What is the Futuristic Way?

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 the future.
Add parameters as available in Future Publisher.
Add Custom Code that we want to Execute in Base Objects.


Now as its Pre-NAV2016 so we will have to add one line of code to invoke the code in Hook Codeunit as shown below.



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
www.sauravdhyani.com

Comments

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 -