Table extension definition

As we mentioned previously, with Dynamics 365 Business Central, you cannot modify an existing table; instead, you need to create a table extension.

A table extension can be defined by using the ttableext snippet:

tableextension Id MyExtension extends MyTargetTable
{
fields
{
// Add changes to table fields here
}

var
myInt: Integer;
}

A tableextension object is defined by an ID and a name (which must be unique) and by the table that must be extended (or altered). Then, inside the fields group, you can add new fields or change existing field properties.

The following code is an example of an extension to the standard Customer table that adds some new fields and changes an existing field property:

tableextension 50100 CustomerExtSD extends Customer
{
fields
{
field(50100; PacktEnabledSD; Boolean)
{
DataClassification = CustomerContent;
Caption = 'Packt Subscription Enabled';
}
field(50101; PacktCodeSD; Code[20])
{
DataClassification = CustomerContent;
Caption = 'Packt Subscription Code';
}

modify("Net Change")
{
BlankZero = true;
}
}
}

In a tableextension object, you can also add new keys to the extended table by adding a keys group, like you can in a table definition. For example, in our previous tableextension object, we've added two new fields, and we want also to create a secondary key on those fields in the Customer table. We can create a key group with the key name and the key fields:

tableextension 50100 CustomerExtSD extends Customer
{
fields
{
field(50100; PacktEnabledSD; Boolean)
{
DataClassification = CustomerContent;
Caption = 'Packt Subscription Enabled';
}
field(50101; PacktCodeSD; Code[20])
{
DataClassification = CustomerContent;
Caption = 'Packt Subscription Code';
}
modify("Net Change")
{
BlankZero = true;
}
}

keys
{
key(PacktKey; PacktCodeSD,PacktEnabledSD)
{

}
}
}
You cannot create a key based on a new field or a standard field, and you cannot alter an existing key in an extended table.

Here, we have defined a secondary key called PacktKey in the Customer table, which consists of two custom fields (PacktCodeSD and PacktEnabledSD). Defining secondary keys is extremely useful for increasing the performance of some calculations, sorting records, and reports.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.66.206