Monday, February 18, 2019

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
https://saurav-nav.blogspot.com/

No comments:

Post a Comment