In this post I will present some important information about the Microsoft Dynamics NAV Document Pattern.
A document in NAV contains a Header with common data and one or more Lines. Each line is linked to the header. Let’s have a look for example at a Purchase Order. As you can see in the bellow image, a Purchase Order document combines two pages (Purchase Order and Purchase Order Subform) and their underlying tables (Purchase Header and Purchase Line):
The Purchase Line table is linked to the Purchase Header by the “Document Type” and “Document No.” fields, meaning that those two fields are common for the tables. There might be also other common fields, like for example, the “Buy-from Vendor No.”. The first two are very important because if we wouldn’t have them in both tables we couldn’t be able to match each line with it’s corresponding header.
If we look at a Purchase Order, we see that the common fields don’t appear by default in the Sales Order Subform, but we can display them as columns or add them in the Subform page (from the Development Environment) to see what happens.
When we create new lines, it’s interesting to have a look at how the common fields are populated in the Purchase Line table in order to have a better understanding of how this pattern is implemented:
So how does the system fill in the common fields ? It’s possible the first thought is that there is C/AL code in the table triggers or in the OnValidate trigger of the fields which automatically populates them. This is partially right. The answer is that some fields are populated with the help of Properties and some fields with C/AL code:
- The “Document Type” field is filled in automatically in the Purchase Line table, when a new line is created by the user, because of the SourceTableView Property of the Subform page:
- “The Document No.” field is filled in with the help of the property SubPageView of the Purchase Line Subform inserted as a Page Part in the Purchase Order Page:
- The “Buy-from Vendor No.” is populated by C/AL code in the OnValidate Trigger of the “No.” field in Purchase Line table:
- The “Line No.” field from Purchase Line table is automatically filled in and incremented for each new line (10000, 20000,30000 etc) because of the AutoSplitKey property with value= Yes of the page Purchase Order Subform. When you set this to Yes, the system will automatically assign auto numbers to the last field of the Primary Key from table:
Even if normally the user does not see all these fields in the page, if we run the tables (Purchase Header and Purchase Line) from the Development Environment we can see that for order 106024 from our example, behind the scenes this is what happens:
- One line is created in the Purchase Header with the “general” information that applies to all lines of the Purchase Order:
- Multiple lines are created in the Purchase Line table with the fields that link each line with the Header (Doc Type, Doc No), the fields that exist in both header and lines but are not meant to link the two tables (ex: “Buy-from vendor No.”) and the rest of the information that is specific for each line:
This post is meant to offer information about some technical concepts related to the Microsoft Dynamics NAV Document Pattern. Before implementing this pattern for custom NAV functionality please read also this post with some general information and analyse in more detail the standard functionality.