A Table Hook to minimize the upgrade work

In a line with the methods introduced by Partner Ready Software I am now upgrading old code to NAV 2013 R2 with the goal to modify the standard objects a little as possible.

I don’t recall Mark, Waldo, Gary or Vjeko speaking about a Table Hook but I decided to go that way anyway.  As an example I have about twenty new field for the Customer Table.  Instead of creating these fields in table 18 I create a new table that I call Customer Hook.  The Hook Table must include the fields from the primary key and the primary key it self from the Master Table.

CustomerHook

The only modification I do in table 18 is a new function

GetHook

In a code where I need to access the new custom fields I use this function to get the Table Hook to work with.

In the Hook table I have a few functions.

HookFunctions

Next I created a Codeunit to hook to the global triggers in Codeunit 1.  This Codeunit forwards the triggers from Codeunit 1 to the Hook Table.

DbHookCodeunit

I need to add four lines to Codeunit 1.

Codeunit1Changes

When all this is ready I am able to create or extend the Customer Page.  Here it is easy to mix together fields from the Customer Table and the Customer Hook Table.

PageFields

For the fields from the Hook Table I can add a Table Relation and a Validate code.

CodeValidate

On the Page I create a local function

SaveFunction

and finally make sure that I get the Hook table matching the Customer on the Page.

GetHookOnPage