NAV Design Pattern – Document Pattern

If you’re just starting with NAV, this pattern is a must-know for any NAV developer or consultant. Thanks to Xavier Garonnat from knk Ingénierie in France for documenting it.

Best regards,

The NAV Patterns team

Meet the Pattern

A document structure contains a header and a set of lines. Each line is linked to the header and could have common data with header.

Know the Pattern

This pattern should be used as a basis to build any document, showing a header and multiple lines in the same page. Basically, a document is at least composed of two tables and three pages, as shown below:

Use the Pattern

You should use it any time you have to capture and store a document.

Example

To build this example from scratch, you will need:

Two tables, one for the header (called “Document Header”), and one for the document lines (called “Document Line”). Each document will be composed of “1 to N” line(s).

Three pages, one for the header, one for the subpage (lines), and the last for the document list obviously.

Add a field “No.” (Code 20): Should be the first field and primary key of your documents, to be driven by Serial No. (See corresponding design pattern)

For this sample, I just added a “Sell-to Customer No.” to this table. Don’t forget to manage deletion of lines with trigger OnDelete().

Table “Document Line”: will store the lines of the document

Add a field “Document No.” (Code 20): Should be the first field and is related to table “Document Header”: set TableRelation to your “Document Header” table

Add a field “Line No.” (Integer): this field will be populated automatically by the subpage page (see AutoSplitKey)

First (Primary) Key must be “Document No.,Line No.”. On table properties, set PasteIsValid to No (to avoid copying/pasting lines, will be implemented by “Copy document”, another pattern).

For my sample, I just add a couple of fields: “Item No.” and “Quantity” to this table (just copy/paste standard fields from “Sales Line” table and delete trigger code, this will insure that each field will be well designed)

Page “Document Subpage”: will display the lines in the main form, and will be in charge of assigning line number automatically.

Create the page for table “Document Line” with the wizard by selecting the ListPart template, add all yours fields except the primary key (“Document No.” and “Line No.”).

Then edit the properties:

Set AutoSplitKey, DelayedInsert and MultipleNewLines to Yes: this combination will make your subpage work as required.

AutoSplitKey is used to set NAV calculate the last field of the key (“Line No.”) with proper numbers (10000, 20000…).

Hi , with Microsoft Dynamics NAV 2015, we saw a change with the way Page "Document Subpage" is working.

For example, you open a document (Sales Invoice) from the listpage and you do a posting in the card page. When the posting is successful, the next document will show in the card page and you can continue to post this sales invoice. However, if you close the page and go back to the listpage, you still see all the same record as before. You need to press the refresh button of the listpage to refresh the list. In the previous version, ths refresh step was not needed. How about the behavior of the Page "Document Subpage” ?