The AL developer environment is evolving with frequent updates. To stay up to date on the latest information and announcements, follow us on the Dynamics NAV Team Blog.

Table Extension Object

The table extension object allows you to add additional fields or to change some properties on a table provided by the Dynamics 365 Business Central service. In this way, you can add data to the same table and treat it as a single table. For example, you may want to create a table extension for a retail winter sports store. In your solution you want to have ShoeSize as an additional field on the customer table. Adding this as an extension allows you to write code for the customer record and also include values for the ShoeSize.

Along with defining other fields, the table extension is where you write trigger code for your additional fields.

When developing a solution for Dynamics 365 Business Central , you will follow the code layout for a table extension as shown in the example below.

Note

Extension objects can have a name with a maximum length of 30 characters.

Snippet support

Typing the shortcut ttableext will create the basic layout for a table extension object when using the AL Language extension in Visual Studio Code.

Properties

Using a table extension allows you to overwrite some properties on fields in the base table. For a list of Table properties, see Table and Table Extension Properties.

Table extension example

This table extension object extends the Customer table object by adding a field ShoeSize, with ID 70000900 and the data type Integer. It also contains a procedure to check if the ShoeSize field is filled in.

tableextension 50115 RetailWinterSportsStore extends Customer
{
    fields
    {
        field(50116;ShoeSize;Integer)
        {
            trigger OnValidate();
            begin
                if (rec.ShoeSize < 0) then
                begin
                   message('Shoe size not valid: %1', rec.ShoeSize);
                end;                    
            end;
        }
    }

    procedure HasShoeSize() : Boolean;
    begin
        exit(ShoeSize <> 0);
    end;

    trigger OnBeforeInsert();
    begin
        if not HasShoeSize then
            ShoeSize := Random(42);
    end;
}

Applies to

Tables

See Also

AL Development Environment
Table Overview
Table Object
Table and Table Extension Properties
Table Keys