Create document tables

Completed

Document tables are secondary transactional tables that enable entries for one or multiple application areas at the same time. They are secondary only in that their information is posted to ledgers through journal tables rather than being posted directly. For most users, document tables are the primary means of entering a transaction.

Because document tables are used for transaction entries, they have more trigger codes than most other table types.

The two kinds of document tables are:

  • Document header

  • Document line

Document header tables

A document header table holds the main transaction information that applies to all lines in the document. For example, for a sales transaction, the Sales Header table contains main information about order or invoices, such as the customer to whom the order or invoice belongs, posting dates, shipping information, and similar information that applies to all lines in the document.

Document line tables

A document line table holds detailed information for the transaction. For example, for a sales transaction, the Sales Line table contains information about each line of the order or invoice. A document line table is a subsidiary table of the document header table.

Like journal tables, document tables are related to many other tables, including master, supplemental, and subsidiary tables. Other table types are rarely related to other document tables.

Document table names

The name of a document header table is the name of the transaction or document plus the word header. For example, the document header table that contains sales transactions is named Sales Header. Each record contains one sale, such as order or invoice.

For example, a document header table that contains finance charge memo transactions is named Finance Charge Memo Header. Each record contains one finance charge memo.

The name of a document line table is the name of the transaction or document plus the word line. For example, the document line table that contains sales transactions is named Sales Line. Each record contains one line from a sale, such as order or invoice.

For example, the document line table that contains finance charge memo transactions is named Finance Charge Memo Line. Each record contains one line from a finance charge memo.

Primary key and other standard fields

For most document header tables, the primary key is a Code type field, named No. and of length 20, that contains the document number. Some document header tables contain multiple types of documents. For example, the Sales Header table contains invoice documents, credit memo documents, sales order documents, and other document types. In these cases, the primary key has two fields:

  • Document Type - Option field

  • No. - Code field of length 20

For most document line tables, the primary key has two fields: a Code type field of length 20 that contains the document number, and an Integer type field named Line No. The code field relates to the document header table and is named according to that table's name (without the word header), followed by that table's primary key field.

For example, the Code type field in the primary key of the Finance Charge Memo Line table is named Finance Charge Memo No.

When the document header table's primary key includes a document type, the primary key of the document line table has the following three fields:

  • Document Type - Option field

  • Document No. - Code field of length 20

  • Line No. - Integer field

The code field relates to the document header table.

Associated pages

A document header table uses a page of type Document to display one header record at a time so you can view and edit the information in the header table. The page name is also the name of the document that is displayed.

For example, the page that shows finance charge memos from the Finance Charge Memo Header table is named Finance Charge Memo. This approach applies even if the table contains multiple types of documents because, in this case, the page is set up to only view information from one type. For example, the page that shows sales invoices from the Sales Header table is named Sales Invoice.

The page contains FastTabs to split the fields into logical groups, which simplifies your ability to edit the information. A document page includes a page part that shows the document lines page.

A document line table uses a ListPart page to display multiple line records at a time. The name of the page is the name of the document followed by either the word lines or subform. None of the primary key fields are included on this page.

This page is filtered by using the SubPageLink property for all the primary key fields, except for the Line No. field, which is automatically handled by the AutoSplitKey property of the page.

The document header table also uses a list page to let you view multiple documents at the same time. The name of this page is the name of the document page followed by the word list. For example, the list page that shows the sales invoices is called Sales Invoice List.

The document header list page uses the CardPageID property to specify the document page that is shown when you view, edit, or create a new document or when you double-click a document in the list.

The following example shows a snippet of the Sales Header table.

table 36 "Sales Header"
{
    Caption = 'Sales Header';
    DataCaptionFields = "No.", "Sell-to Customer Name";
    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])
        {
            TableRelation = Customer;
        }
        field(3; "No."; Code[20])
        {
        }
        field(4; "Bill-to Customer No."; Code[20])
        {
            TableRelation = Customer;
        }
        ...
    }
    keys
    {
        key(Key1; "Document Type", "No.")
        {
            Clustered = true;
        }
    }
}

The following example shows a snippet of the Sales Line table.

table 37 "Sales Line"
{
    Caption = 'Sales Line';
    DrillDownPageID = "Sales Lines";
    LookupPageID = "Sales Lines";

    fields
    {
        field(1; "Document Type"; Option)
        {
            OptionMembers = Quote,"Order",Invoice,"Credit Memo","Blanket Order",
                            "Return Order";
        }
        field(2; "Sell-to Customer No."; Code[20])
        {
            TableRelation = Customer;
        }
        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])
        {
            TableRelation = if (Type = Const(" ")) "Standard Text"
            else
            if (Type = Const("G/L Account") "G/L Account" 
            else
            if (Type = Const(Resource)) Resource
            else
            if (Type = Const("Fixed Asset")) "Fixed Asset"
            else
            if (Type = Const("Charge (Item)")) "Item Charge"
            else
            if (Type = Const(Item) Item; 
        }
        ...
        field(11; Description; Text[100])
        {            
        }
        ...
    }
    keys
    {
        key(Key1; "Document Type", "Document No.", "Line No.")
        {
            Clustered = true;
        }
    }
}

Document history tables

Document history tables have the same relationship to document tables that ledger tables have to journal tables. When a document is posted, part of that posting process is copying the document tables to their corresponding document history tables. To aid with that copying process, the document history table contains fields that have the same field numbers, names, and properties as the original document tables.

Generally, because document history tables record posted transactions, they can't be edited by the user. However, they can be deleted under certain circumstances. For example, you can delete a posted sales invoice if it was printed. Other than these few distinctions, document history tables and pages are the same as document tables and pages.