Hi,
I would like to know if anyone here on the forum has experience with the Hooks Pattern discussed on the design pattern page and also on Waldo's blog?
I am interested in knowing how to deal with small assignments in the code, e.g like:
SalesLine.Quantity := MyNewLine.Quantity
According to the pattern everything is pushed to the hook function, so what about small one-line assignments. Do you also push them?
And how to handle situations where you need the return value to decide whether to exe one part of the code or another?
I would like to see some more examples than shown in the article and hear about general experience with the pattern.
/zeon
Comments
Yes, also small assignments, because sometimes/often it will not be the last line you need.
Tino Ruijs
Microsoft Dynamics NAV specialist
Have you worked with the pattern, and what is your experience...any shortcomings?
And what about naming conventions when I add code to e.g "Quantity - OnValidate". What's the preferred naming for that hook function? OnQuantityOnValidate or OnValidateQuantity...or...
Gonna do that. :-)
I've learned about the pattern from Waldo at NAVTechdays.
So I started using it in my latest projects. But I do not yet use naming conventions. Gonna do that in my next project I think.
Tino Ruijs
Microsoft Dynamics NAV specialist
I think in general it's a good idea to ensure that you don't corrupt a standard object when you update and/or merge. On the other hand, you need a lot of additional codeunits (depending on how many parts of NAV you use).
We name it e.g. T37OnQuantityValidate. So, basically it's [Object]On[Fieldname][Action].
But a "normal" customization developer would not do this, no advantage, and hard to explain to the customer why they need to spend money on buying Codeunits.
Here us how I done it since about 2002: I pretty much automatcally sell table, form/page, report designer with every project and the objects that come with it. If the customer is called Cronus Ltd. the first thing to do is to make a Cronus Setup table. And form/page. Any change requested gets a setting here like a checkmark to turn off and on, for safety and it also serves as a quick documentation, just looking at this setup reminds you what was done for this customer.
And pretty much every code is a function in this table. What is even the point of codeunits, other than to regulate licence ranges or user rights? A function is a function everywhere. So, yes, it is then filled with functions like TableSalesLineQuantityValidateBefore and TableSalesLineQuantityValidateAfter. This makes merging a whole lot easier.
I think it would be useful if add-on patterns and customization patterns would be more separated. This is a good customization pattern.
Nice solution such a setup table!
Tino Ruijs
Microsoft Dynamics NAV specialist
The localized BE add-on on it's turn also wants to further customize the OnValidateQuantity hook. Would you have to add the extra hook in the hook codeunit? Or create a second hook in the original code?
On top of that, the BE add-on is used for a customer implementation, needing extra customisations on the hook.
At the end, how would the 3 hooks (W1, BE, Customer) have to be implemented and how would that increase the readibility of the application code?
A good customization pattern. You have a customer called e.g. Cronus. They buy table, form, report designer. Get 10 tables. You create table 50000 as e.g. Cronus Customizations Setup. Same way as e.g. Inventory Setup. For every customization you do, you put there a configuration and at least one boolean field that tells you to turn the customization on or off in a certain company. This is also very useful because this page and table works basically as a simple documentation. When you hand over your client to your support department, you can show them this table and page and tell the support basically these are the custom stuff here, rest is standard.
And then you can put all your hook functions on that table.
I also think in 2016 these are events now, not hooks? Did not look into it yet.