change nav 1-patterns formatting
This commit is contained in:
parent
ba12637e35
commit
7e4e21d223
54 changed files with 211 additions and 250 deletions
|
|
@ -8,7 +8,7 @@ _By Eric Wauters ([waldo][anchor0]), Partner-Ready-Software_
|
|||
|
||||
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.
|
||||
|
||||
Description
|
||||
## Description
|
||||
|
||||
When doing development over years, by different developers with different mindsets, the standard codebase gets changed a lot, adding multiple lines of code, adding local and global variants, adding or changing keys, changing existing business logic, ... . In other terms, the standard text objects are being changed all over the place.. .
|
||||
|
||||
|
|
@ -28,42 +28,42 @@ I recommend to use this concept on:
|
|||
|
||||
## Usage
|
||||
|
||||
Step 1 - if it doesn't exist yet - you create your Hook Codeunit. As the name assumes .. this is always a codeunit. We apply the following rules to it:
|
||||
**Step 1** - if it doesn't exist yet - you create your Hook Codeunit. As the name assumes .. this is always a codeunit. We apply the following rules to it:
|
||||
|
||||
* One Hook always hooks into one object. Which basically means that I will only declare this new codeunit in one other object (which is its parent object)
|
||||
* The naming convention is: "The\_Original\_Object\_Name Hook". Naming conventions are important, just to find your mapped object, and also to be able to group the Hooks.
|
||||
|
||||
Step 2, you create the hook, which is basically a method (function) in your codeunit. The naming is important:
|
||||
**Step 2**, you create the hook, which is basically a method (function) in your codeunit. The naming is important:
|
||||
|
||||
* The naming of the hook should NOT describe what it is going to do (So, examples like "CheckMandatoryFields", "FillCustomFields" should not be used as a hook)
|
||||
* The naming of the hook should describe WHERE the hook is placed, not what the hook will be doing (as nobody is able to look into the future .. :-))
|
||||
* To help with the naming, it is a good convention to use the "On"-prefix for these triggers. This way, it's very clear what are hooks, and what aren't..
|
||||
|
||||
Step 3, it's time to hook it to its corresponding object and right place in the business logic of that object. You do this by declaring your codeunit as a global in your object, and using the created hook function on its place in the business logic. This way, these one-liners apply:
|
||||
**Step 3**, it's time to hook it to its corresponding object and right place in the business logic of that object. You do this by declaring your codeunit as a global in your object, and using the created hook function on its place in the business logic. This way, these one-liners apply:
|
||||
|
||||
* A Hook Codeunit is only used once in one object only (its corresponding object)
|
||||
* A Hook (function) is used only once in that object. As a consequence, changing the parameters has no consequence: you only need to change one function-call
|
||||
* The codeunit is declared as a global. That exact global is the only custom declaration in the existing object .. Everything else is pushed to the hook-codeunit.
|
||||
|
||||
Step 4, implement your business logic in the hook. Do this in the most atomic way, as there is a good chance that this same hook is going to be used for other business logic as well. Best is to use a one-line-function-call to business logic, so that the Hook Function itself stays readable.
|
||||
**Step 4**, implement your business logic in the hook. Do this in the most atomic way, as there is a good chance that this same hook is going to be used for other business logic as well. Best is to use a one-line-function-call to business logic, so that the Hook Function itself stays readable.
|
||||
|
||||
## Example
|
||||
|
||||
Suppose, we want to add business logic just before posting a sales document. In that case, we have to look for the most relevant place, which is somewhere in the "Sales-Post" codeunit. So:
|
||||
|
||||
Step 1: create codeunit "Sales-Post Hook"
|
||||
**Step 1**: create codeunit "Sales-Post Hook"
|
||||
|
||||
[![ ][image0]][anchor1]
|
||||
|
||||
Step 2: create the hook function "OnBeforePostDocument"
|
||||
**Step 2**: create the hook function "OnBeforePostDocument"
|
||||
|
||||
[![ ][image1]][anchor2]
|
||||
|
||||
Step 3: declare a global in the "Sales-Post"-codeunit, called "SalesPostHook". Then, call the Hook Function that you created in Step 2 in the right place.
|
||||
**Step 3**: declare a global in the "Sales-Post"-codeunit, called "SalesPostHook". Then, call the Hook Function that you created in Step 2 in the right place.
|
||||
|
||||
[![ ][image2]][anchor3]
|
||||
|
||||
Step 4: implement the business logic, by calling out to a new function. And implement the test-codeunit.
|
||||
**Step 4**: implement the business logic, by calling out to a new function. And implement the test-codeunit.
|
||||
|
||||
[![ ][image3]][anchor4]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue