Understanding Objects in Business Central, Part 1: The Language and the Table

A blueprint-style diagram of a Business Central table showing its properties, fields, keys, and triggers.

Picture the scene: a sharp C# developer joins a Business Central project. They open Visual Studio Code, create a new file, and type public class Salesperson. Nothing works. There is no constructor to write. There is no base class to inherit from. Someone on the team tells them the Salesperson already exists, and they are not allowed to change it.

That first hour is disorienting. It is also completely normal.

I have watched talented developers go through this more times than I can count. The problem is never their skill. It is their map. They arrive with a map drawn for general-purpose, object-oriented languages, and Business Central is a different country.

This series is the new map.

About This Series

This is the first post in Understanding Objects, a series that walks through the building blocks of AL development one object at a time. Each post stands on its own, so start wherever you need to.

  1. Tables (you are here)
  2. Pages
  3. Reports
  4. Codeunits
  5. Queries
  6. XMLports
  7. Enums
  8. Permission Sets
  9. Interfaces
  10. Extension Objects

Meet Alexander Bikes

Every code example in this series follows one fictitious company. Alexander Bikes designs, builds, and sells bicycles out of Gainesville, Florida, and it is changing how it pays its sales team in two ways.

  • Tiered commission by margin and product type. A bike sold at a healthy margin earns a bigger percentage than one sold at a deep discount, and accessories follow their own scale.
  • Pay when paid. A salesperson earns commission only after the customer has paid for the purchase, not when the invoice goes out.

The standard Commission % field on a salesperson card is one flat rate. It cannot do either. So Alexander Bikes is building a custom sales commission module in Business Central, one object at a time, right alongside this series.

Each part shows only the pieces of the module that explain its object. Once the series has covered every object, a later post brings them together in a step-by-step walkthrough of the complete commission project, from the first table to the last extension.

A diagram introducing Alexander Bikes, a fictitious Gainesville bike company, its two commission requirements, and the ten objects the series uses to build its commission module.

AL Is a Language Built for One Job

AL is the programming language behind Microsoft Dynamics 365 Business Central. It descends from C/AL, the language that powered Navision for decades, and it keeps that family’s Pascal flavor: begin and end instead of curly braces, := for assignment, and keywords that read almost like English.

C# and C++ are general-purpose languages. You can build a game, a device driver, a web server, or a payroll engine with them. AL does not try to do any of that. It exists to describe and work with business data inside Business Central, and nowhere else.

That narrow focus is not a weakness. It is the whole design.

Under the hood, the Business Central server turns your AL into .NET code. So your C# instincts are not wrong. They just live one floor down, in a basement you never have to visit.

Object-Based Is Not Object-Oriented

Microsoft describes the AL extension model as object-based, and the wording is deliberate. In C# or C++, an object is whatever you define. You write a class, give it fields and methods, inherit from another class, and create as many instances as you like with new.

AL works from what I call the fixed menu. You do not invent new kinds of objects. You order from a short list of object types the platform already understands (tables, pages, codeunits, reports, and a handful more), and you fill them in.

A comparison showing C# and C++ developers defining any class they want, while AL developers choose from a fixed list of object types.

Here is how the core ideas line up.

ConceptC# and C++AL
Defining a new typeWrite any class or struct you wantChoose from a fixed set of object types
InheritanceClass inheritance (C++ even allows multiple)None. You extend objects with extension objects and events
Creating an instancenew and a constructorDeclare a variable. The platform handles the rest
MemoryManual in C++, garbage-collected in C#Managed entirely by the platform
Saving dataYour choice of database, ORM, or fileTables are the database
PolymorphismVirtual methods and interfacesInterfaces, implemented by codeunits and enums
User interfaceBuild it yourselfDescribe it in a page. The client renders it
Where code livesAnywhere you put itInside objects, in procedures and triggers

AL is not frozen in time, though. Interfaces arrived in Business Central 2020 release wave 1, and 2024 release wave 2 added the ability for one interface to extend others. That is the closest AL comes to classic inheritance, and it gets its own post in Part 9.

What Is on the Menu

The list is short enough to memorize, and that is part of the point.

A grid of AL object types grouped by role, with the table object highlighted as the starting point.
  • Data: table, table extension, query
  • Presentation: page, page extension, page customization, report, report extension, profile
  • Logic: codeunit, interface, enum, enum extension
  • Integration: XMLport, control add-in
  • Security: permission set, permission set extension

What You Give Up and What You Get

Developers coming from C# often feel boxed in by the fixed menu at first. Look at what comes with it, though. You never write a database connection string. You never map a class to a SQL table. You never hand-build a form, a login screen, a permission check for every record, or a separate version of the app for phones. The platform does that plumbing for you, for every object, every time.

AL trades the freedom to invent any shape for freedom from the plumbing.

You give up the blank canvas. You get a platform that already knows what an invoice is.

Every Object Has a Number and a Name

Every AL object carries an ID and a name, and both must be unique within that object type. Microsoft’s base application occupies the lower ranges. Per-tenant extensions (customizations built for a single company) use IDs 50,000 to 99,999, and AppSource partners receive their own assigned ranges. Your extension declares its range in its app.json file.

Names follow a convention worth adopting on day one: give every object a prefix or suffix unique to your organization. The Alexander Bikes examples use ABK. That small habit keeps your objects from colliding with someone else’s extension in the same environment.

Tables Come First

Every object in Business Central eventually leads back to a table. Pages display table data. Reports read it. Codeunits change it. Queries join it. APIs expose it. Start anywhere in the system, pull the thread, and you arrive at a table.

In a typical C# application, data lives in three places at once: a class that holds it in memory, a repository or ORM that moves it, and a database schema that stores it. Business Central collapses all three into one object.

A table in AL is not just a schema. It is a schema with opinions.

It knows what its columns are. It also knows which values are allowed, how it relates to other tables, what to fill in by default, and what must be true before a record can be deleted. Those opinions travel with the data everywhere it goes.

Anatomy of a Table

Microsoft defines four sections in a table, and the order matters:

  1. Properties that describe the table as a whole
  2. Fields that define the columns
  3. Keys that define how records are identified and sorted
  4. Code, including triggers, that runs against the table

Most real tables also include a field groups section between keys and code.

Alexander Bikes starts its commission module where every module starts: with a place to store the rules. The first table holds commission tiers. Each tier says, for one product type, “a sale at this margin or higher earns this rate.” Here is what the sales team’s new scale might look like as data:

Product TypeMargin of at LeastCommission Rate
Bikes0%2%
Bikes20%4%
Bikes35%6%
Accessories0%5%
Accessories40%8%

A bike sold at a 25% margin earns 4%. The same bike discounted down to a 15% margin earns 2%. Business Central already groups products by item category, so the tier table uses item categories as its product types.

Stepped charts showing Alexander Bikes commission rates rising with margin, with separate tiers for bikes and accessories.

Here is the table that holds those tiers.

A diagram dividing the Alexander Bikes commission tier table into five sections: properties, fields, keys, field groups, and triggers.
table 50100 "ABK Commission Tier"
{
    Caption = 'Commission Tier';
    DataClassification = CustomerContent;

    fields
    {
        field(1; "Item Category Code"; Code[20])
        {
            Caption = 'Item Category Code';
            TableRelation = "Item Category";
            NotBlank = true;
        }
        field(2; "Item Category Description"; Text[100])
        {
            Caption = 'Item Category Description';
            FieldClass = FlowField;
            CalcFormula = lookup("Item Category".Description where(Code = field("Item Category Code")));
            Editable = false;
        }
        field(3; "Minimum Margin %"; Decimal)
        {
            Caption = 'Minimum Margin %';
            DecimalPlaces = 0 : 2;
            MinValue = 0;
            MaxValue = 100;
        }
        field(4; "Commission %"; Decimal)
        {
            Caption = 'Commission %';
            DecimalPlaces = 0 : 2;
            MinValue = 0;
            MaxValue = 100;
        }
        field(5; "Starting Date"; Date)
        {
            Caption = 'Starting Date';
        }
        field(6; "Ending Date"; Date)
        {
            Caption = 'Ending Date';

            trigger OnValidate()
            begin
                if ("Ending Date" <> 0D) and ("Ending Date" < "Starting Date") then
                    Error(EndBeforeStartErr);
            end;
        }
        field(7; Blocked; Boolean)
        {
            Caption = 'Blocked';
        }
    }

    keys
    {
        key(PK; "Item Category Code", "Minimum Margin %", "Starting Date")
        {
            Clustered = true;
        }
        key(Dates; "Starting Date", "Ending Date")
        {
        }
    }

    fieldgroups
    {
        fieldgroup(DropDown; "Item Category Code", "Minimum Margin %", "Commission %")
        {
        }
    }

    trigger OnInsert()
    begin
        if "Starting Date" = 0D then
            "Starting Date" := WorkDate();
    end;

    trigger OnDelete()
    begin
        TestField(Blocked, true);
    end;

    var
        EndBeforeStartErr: Label 'The ending date cannot be earlier than the starting date.';
}

You do not have to type that skeleton from scratch. With the AL Language extension installed in Visual Studio Code, typing ttable generates the basic layout.

Visual Studio Code showing the ttable snippet generating an empty AL table.

Now let’s walk through it section by section.

Properties: The Table’s Identity

The block at the top describes the table itself. Caption is the name users see. DataClassification tells Business Central what kind of data the table holds (customer content, personal information, system data, and so on), which matters for privacy and compliance. Other common properties connect the table to its default list page and control whether other extensions can extend it.

Fields: The Columns, Plus the Rules

Each field declares an ID, a name, and a data type: field(1; "Item Category Code"; Code[20]). Inside the braces go its properties and, optionally, its own triggers. Notice how much of the commission policy lives right here. TableRelation means a tier can only point at an item category that exists. MinValue and MaxValue keep both percentages between 0 and 100 before any code runs.

The field ID deserves special respect. Treat field numbers like a foundation. Once data sits on top of them, you do not move them.

A few data types do most of the work:

TypeUse It For
Code[n]Identifiers like item category codes and salesperson codes. Stored in uppercase, trimmed automatically
Text[n]Names, descriptions, and free text
Integer / BigIntegerWhole numbers and entry numbers
DecimalAmounts, quantities, rates, and margins
Date / Time / DateTimePoints in time
BooleanYes or no flags
EnumA fixed list of choices, such as a status (Part 7 covers these)
Blob / MediaFiles, images, and large content

Field Classes: Stored, Calculated, and Filters

Look again at "Item Category Description". It has FieldClass = FlowField, which means the table never stores it. Business Central looks it up on demand from the Item Category table, so renaming a category never leaves a stale copy behind in the commission tiers.

A FlowField is a question the table knows how to ask. It is not an answer the table keeps.

Pages calculate FlowFields automatically. Code must ask for them with CalcFields() before reading the value, and forgetting that step is a classic first-week bug. AL has three field classes in all:

  • Normal: stored in the database like any column
  • FlowField: calculated from other tables when requested (lookups, sums, counts, existence checks)
  • FlowFilter: holds a filter value that FlowFields can use, such as a date range
A diagram comparing Normal fields that are stored, FlowFields that are calculated on demand, and FlowFilters that supply filter values.

Keys: How Records Are Found

The first key in a table is the primary key, and it must uniquely identify every record. No single field can do that for a commission tier. Bikes have three tiers, and the same tier can be replaced next season with a new rate. So the primary key combines all three facts that make a tier unique: the product type, the margin floor, and the starting date.

The primary key also sets the table’s default sort order. That detail looks minor now and does real work later in this post.

Additional keys are secondary keys. They help Business Central sort and filter efficiently, such as the Dates key that lets finance review which tiers expire this quarter. Keys are not free, though. Each one adds work every time a record is written, so add them for real access patterns, not just in case.

Field Groups: The Small Detail Users See Every Day

Field groups decide which fields appear in specific places in the client. The DropDown group controls the columns a user sees when picking a record from a lookup, so anyone choosing a tier sees its product type, margin floor, and rate at a glance. The Brick group controls what shows on tiles. It is a two-line section that shapes thousands of clicks.

Triggers: Where the Opinions Live

Tables have four record-level triggers: OnInsert, OnModify, OnDelete, and OnRename. Fields have their own, most importantly OnValidate. In the commission tier table, OnInsert fills in a default starting date, OnDelete refuses to remove a tier until someone blocks it first (commission history should not lose the rules it was paid under), and the Ending Date’s OnValidate rejects an ending date earlier than the starting date.

Here is the part that catches nearly every C# developer once.

Table triggers do not run automatically when code writes data. A user creating a record on a page always runs OnInsert. Code calling Insert() does not. Code must request the trigger explicitly with Insert(true), and the same goes for Modify(true) and Delete(true).

Field validation follows the same pattern. Typing a value on a page runs OnValidate. Assigning a value in code with := does not. Calling Validate() does.

CommissionTier."Ending Date" := CalcDate('<CY>', WorkDate());          // sets the value, skips OnValidate
CommissionTier.Validate("Ending Date", CalcDate('<CY>', WorkDate()));  // sets the value and runs OnValidate
CommissionTier.Modify(true);                                          // saves the record and runs OnModify

Assignment is not validation. It is just assignment.

Most data problems in a Business Central customization trace back to code that skipped the rules the table was built to enforce.

A diagram showing that page input always runs table and field triggers, while AL code runs them only when it calls Validate or passes true to Insert, Modify, or Delete.

A Record Is a Window, Not a Row

One more mental shift before we wrap up. C# developers tend to expect a record variable to be an object that represents one row. An AL Record variable is closer to a window onto the table. It shows one row at a time, carries its own filters and sort order, and moves through the table as you ask.

Here is the question at the heart of Alexander Bikes’ new plan: what rate does this sale earn?

procedure GetCommissionPct(ItemCategoryCode: Code[20]; MarginPct: Decimal): Decimal
var
    CommissionTier: Record "ABK Commission Tier";
begin
    CommissionTier.SetRange("Item Category Code", ItemCategoryCode);
    CommissionTier.SetFilter("Minimum Margin %", '<=%1', MarginPct);
    CommissionTier.SetFilter("Starting Date", '<=%1', WorkDate());
    CommissionTier.SetFilter("Ending Date", '%1|>=%2', 0D, WorkDate());
    CommissionTier.SetRange(Blocked, false);
    if CommissionTier.FindLast() then
        exit(CommissionTier."Commission %");
    exit(0);
end;

The filters narrow the window to active tiers for this product type that the sale’s margin qualifies for. FindLast() then moves the window to the last of them. Remember that the primary key sorts tiers by margin floor, so the last qualifying tier is the highest one the sale earned. A bike at 25% margin passes the 0% and 20% tiers, fails the 35% tier, and lands on 4%.

No loop. No sorting code. The key did the work.

When you need every matching row instead of one, FindSet() and Next() step the window forward a row at a time. That rhythm shows up in almost every codeunit you will ever read, and Part 4 spends real time on it. Calculating the margin itself belongs in a codeunit too.

A diagram of an AL Record variable as a filtered window over the commission tiers, landing on the highest tier a 25 percent margin qualifies for.

What About Tables You Did Not Create?

Everything in this post describes a table you create. Real projects also depend on tables they did not create: Customer, Item, Cust. Ledger Entry, and the rest of the base application. You cannot open those and edit them, and pay when paid will need exactly that kind of change. We will cover how to handle it when we come to extension objects in Part 10.

What’s Next

Alexander Bikes now has a place to store its commission rules. Nobody can see them yet. (The full build, every object in order, comes in the walkthrough at the end of the series.)

In Part 2 we move from storage to sight: pages, the object that turns a table into something a person can actually use. Pages are where the fixed menu starts to feel generous, because you describe what the user needs and the client builds the screen.

Until then, open Visual Studio Code, type ttable, and build a table of your own. Give it a few fields, a key, and one rule worth enforcing.

Start with the table. Everything else is built on it.

Illustration of David Rhue, smiling

About the author

David Rhue is The BC Dr., a Business Central consultant who helps organizations diagnose what's broken and get more from their ERP.

David’s book, The Book on BC, arrives October 12, 2027.

More about David

Similar Posts