Create the customer table extension object

Completed

The Customer table, like many other tables, is part of the Business Central service and it can't be directly modified by developers. To add more fields or to change properties on this table, developers must create a new type of object: a table extension.

For your customer rewards extension, you need to add a field to the Customer table. The following code creates a table extension for the Customer table and adds the RewardPoints field.

tableextension 50100 Customer extends Customer
{
  fields
  {
    field(10001; RewardPoints; Integer)
    {
      Caption = 'Reward Points';
      DataClassification = CustomerContent;
      MinValue = 0;
    }
  }
} 

Note

If you create this table extension in your project and you get a compilation error that the Customer table is unknown, it probably means you have not downloaded the symbols yet in your VSCode project.

To download symbols, follow these steps:

  1. In VScode, in the Command Palette, select AL: Download Symbols.

  2. The first time you download symbols, you'll be asked to authenticate as the developer for the specific tenant. A message box will appear at the right bottom of the screen. Select it. Your browser will open. Paste the code and then authenticate with the exact same credentials that you use in your BC Saas environment.

  3. After that, close the browser window and the symbols will start to download.

  4. When the symbols are downloaded, in your VSCode project there should be a folder named: .alpackages containing the Application, Base and 2 System apps.

The MinValue property sets the minimum value for a field. The field setting is checked during validation. Validation occurs only if the field or control value is updated through the user interface, for example, if a value is updated on a page or if a field is updated in a table directly. If a field is updated through application code, then the MinValue property isn't validated.

Important notes to remember about table extension objects include:

  • Only tables with the Extensible property set to true can be extended.

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

  • System and virtual tables can't be extended. System tables are created in the ID range of 2,000,000,000 and above.

  • In an extension, you can only create one table extension object for a given table. In other words, you can have multiple table extension objects in an extension if they all extend different tables. You can create multiple extensions (apps) that extend the same table object.