Create a document page

Completed

After master tables and pages are in place, the next step is to implement the functionality that lets users perform transactions with the master data. Users can enter transactional information into Business Central in several ways. Documents are intuitive features that enable users to enter and manage transactions in a straightforward way, and they consist of a header table and lines table.

Almost every functional area of Business Central includes various types of documents that let users create and manage transactions. Documents are frequently complex and span multiple functional areas, such as sales orders. You can use sales orders to manage shipments and invoicing of goods to customers. Additionally, you can use them to coordinate shipping activities with the warehouse department or manufacturing activities with the production department. Documents can also be simple and manage a narrow area of functionality in a single functional area. For example, you can send reminders to customers about overdue payments.

A document page (also known as a Header/Line or a Master/Detail page) combines FastTabs, such as those found in card pages, with the ListPart page. The ListPart page displays, in a single page, records from two tables with a one-to-many relationship. The document page acts as a master page for the header or main table. The sub page of the ListPart shows the related records from the lines or detail table.

Diagram of the document creation structure.

The following screenshot shows a document page with the ListPart lines in red.

Screenshot of a document page with ListPart lines.

In the previous example, the Sales Order page (page 42) is used to create, view, or change sales order documents. Like card pages, the Sales Order page displays fields from the header table that are grouped in several FastTabs (General, Invoice Details, Shipping and Billing, and so on). In addition to these FastTabs, the page also contains a subpart that displays the records from the lines table that are related to the header table. For the Sales Order page, the main page is associated with the header table, Sales Header (table 36). The Sales Order Subform sub page (page 46) is associated with the lines table, Sales Line (table 37). The two pages are linked by the Document Type and Document No. fields, which define the relationship between the Sales Header table and the Sales Line table.

The two table definitions are shown in the following code snippet.

table 36 Sales Header

{
    LookupPageID = "Sales List";

    fields
    {
        field(1; "Document Type"; Option)
        {
            OptionMembers = Quote,"Order",Invoice,"Credit Memo","Blanket Order",
"Return Order";
        }
        field(2; "Sell-to Customer No."; Code[20])
        {
        }
        field(3; "No."; Code[20])
        {
        }
        field(4; "Bill-to Customer No."; Code[20])
        {
        }
        field(5; "Bill-to Name"; Text[100])
        {
        }
        field(6; "Bill-to Name 2"; Text[50])
        {
        }
        field(7; "Bill-to Address"; Text[100])
        {
        }
        field(8; "Bill-to Address 2"; Text[50])
        {
        }
        field(9; "Bill-to City"; Text[30])
        {
        }
        ...
        field(19; "Order Date"; Date)
        {
        }
        field(20; "Posting Date"; Date)
        {
        }
        field(21; "Shipment Date"; Date)
        {
        }
        ...
    }

    keys
    {
        key(Key1; "Document Type", "No.")
        {
            Clustered = true;
        }
    }
}

table 37 Sales Line

{
    fields
    {
        field(1; "Document Type"; Option)
        {
            OptionMembers = Quote,"Order",Invoice,"Credit Memo","Blanket Order",
"Return Order";
        }
        field(2; "Sell-to Customer No."; Code[20])
        {
        }
        field(3; "Document No."; Code[20])
        {
            TableRelation = "Sales Header"."No." where("Document Type" = 
field("Document Type"));
        }
        field(4; "Line No."; Integer)
        {
        }
        field(5; Type; Option)
        {
            OptionMembers = " ","G/L Account",Item,Resource,"Fixed Asset",
"Charge (Item)";
        }
        field(6; "No."; Code[20])
        {          
        }
        field(7; "Location Code"; Code[10])
        {     
        }
    }
    keys
    {
        key(Key1; "Document Type", "Document No.", "Line No.")
        {
            Clustered = true;
        }
    }
}

After you've created the header and line tables, you can create a document page and the ListPart page. The following example shows the Sales Order Subform page, based on the Sales Line table. This page has a PageType of ListPart (therefore, it uses a repeater). The DelayedInsert and AutoSplitKey properties are set to true. The primary key fields (Document Type, Document No., and Line No.) are not used within the repeater.

The following code snippet shows the Sales Order Subform page (page 46).

{
    AutoSplitKey = true;
    DelayedInsert = true;
    PageType = ListPart;
    SourceTable = "Sales Line";
    SourceTableView = where("Document Type" = filter(Order));

    layout
    {
        area(content)
        {
            repeater(Control1)
            {
                field(Type; Type)
                {
                }
                field("No."; "No.")
                {
                }
                field(Description; Description)
                {
                }
                field(Quantity; Quantity)
                {
                }
                field("Unit Price"; "Unit Price")
                {
                }
                field("Line Discount %"; "Line Discount %")
                {
                }
                field("Line Amount"; "Line Amount")
                {
                }
                field("Amount Including VAT"; "Amount Including VAT")
                {
                }
                ...
            }
        }
    }
}

This Sales Order Subform page will be used as a part on the Sales Order document page. Therefore, you should use a control of type part instead of field. Within the part type, you can use the SubPageLink property to link the two pages based on their primary key.

The document page has a PageType property of Document. In this example, the source table is filtered with the SourceTableView to only show the records of type Order.

The following code snippet shows an example of the Sales Order document page (page 42).

{
    PageType = Document;
    SourceTable = "Sales Header";
    SourceTableView = where("Document Type" = filter(Order));

    layout
    {
        area(content)
        {
            group(General)
            {
                field("No."; "No.")
                {
                }
                field("Sell-to Customer No."; "Sell-to Customer No.")
                {
                }
                field("Sell-to Customer Name"; "Sell-to Customer Name")
                {
                }              
                field("Sell-to Contact"; "Sell-to Contact")
                {
                }
                field("Document Date"; "Document Date")
                {
                }
                ...
            }
            part(SalesLines; "Sales Order Subform")
            {
                SubPageLink = "Document No." = field("No.");
                UpdatePropagation = Both;
            }
            group("Invoice Details")
            {
                field("Currency Code"; "Currency Code")
                {
                }
                field("Prices Including VAT"; "Prices Including VAT")
                {
                }
                field("VAT Bus. Posting Group"; "VAT Bus. Posting Group")
                {
                }
        }
        ...
        }
    }
}

Provider property

The ListPart page type is used to create subforms that display records with line details, such as the sales lines in the previous example. However, pages of type ListPart and CardPart are also often used in the FactBox area. This information area is located on the right side of a page. The FactBox area is used to display more information about an entity that is displayed in the Content area.

The following screenshot shows that Customer Details is a FactBox that displays more information about the customer that is selected in the header of the document page. Because a page can only be linked to one source table, you can use page parts to display information coming from other tables.

Screenshot of the customer details in a FactBox.

To link the part with the document page, use the SubPageLink property of the part control.

The following code snippet shows an example of a FactBox area.

{
part(Control1900316107; "Customer Details FactBox")
    {
        SubPageLink = "No." = field("Sell-to Customer No.");
    }
}

If you want to display more information about the selected item in the Sales Order Subform, the SubPageLink property only allows you to link to the document page (the Sales Header table) and not the subform (the Sales Line table).

Screenshot of the item details invoicing section of the sales order.

You can use the Provider property to specify that your part in the FactBox area should not be linked to the document page but to another part on the document page. In the Provider property, you can specify the name of the other page part. In the following example, the page part that displays the Sales Order Subform has the name SalesLines. That name is used in the Provider property of the Item Invoicing FactBox part that displays more information about the selected item in the SalesLines part. By using that Provider property, you can link the Item table with the Sales Line table in the SubPageLink property.

The following code snippet shows an example of the Sales Order subform (page 42).

{
    PageType = Document;
    SourceTable = "Sales Header";
    SourceTableView = where("Document Type" = filter(Order));

    layout
    {
        area(content)
        {
            group(General)
            {
                field("No."; "No.")
                {
                }
                ...
            }
            part(SalesLines; "Sales Order Subform")
            {
                SubPageLink = "Document No." = field("No.");
                UpdatePropagation = Both;
            }
        ...
        }
        area(factboxes)
        {
         part(Control1900316107; "Customer Details FactBox")
            {
                SubPageLink = "No." = field("Sell-to Customer No.");
            }
            part(Control1901314507; "Item Invoicing FactBox")
            {
                Provider = SalesLines;
                SubPageLink = "No." = field("No.");
            }
        }
    }
}