Table extension object
The table extension object allows you to add extra fields or to change some properties on a table provided by Business Central. In this way, you can add data to the same table and treat it as a single table. For example, you might want to create a table extension for a retail winter sports store. In your solution you want to have ShoeSize
as an extra 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 extra fields.
When developing a solution for Business Central, you can follow the code layout for a table extension as shown in the example below.
Important
Only tables with the Extensible Property set to true can be extended.
Note
Extension objects can have a name with a maximum length of 30 characters.
Important
System and virtual tables cannot be extended. System tables are created in the ID range of 2.000.000.000 and above. For more information about object ranges, see Object ranges.
Important
Extending tables from Dynamics 365 for Sales isn't currently supported.
Using a table extension to add a key to the base table
Just like in the table object, you can define keys for fields added in the table extension. But you can also add keys for fields that only exist on the table you extend, in case you want to extend the keys provided in the base table definition. See Table keys for examples on how to define keys in a table extension.
Snippet support
Typing the shortcut ttableext
creates the basic layout for a table extension object when using the AL Language extension for Microsoft Dynamics 365 Business Central 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.
Add tooltips on table fields
Starting in Business Central 2024 release wave 1, you can define tooltips on table fields. When a tooltip is defined on a table field, any page that uses the field automatically inherits the tooltip.
For more information, see Add tooltips to table and page fields.
Table extension syntax
tableextension Id MyExtension extends MyTargetTable
{
fields
{
// Add changes to table fields here
}
var
myInt: Integer;
}
Table extension example
This table extension object extends the Customer table object by adding a field ShoeSize
, with ID 50116 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;
}
Related information
AL development environment
Table overview
Table object
Table, table fields, and table extension properties
Table keys