Can you see the forest for all the tree controls?

In this video, I take a look at Business Central’s ability to collapse row, also known as a tree control and demonstrate how easy you can use this

https://youtu.be/d-dpkY0k6cE

In this video, Erik explores a rarely used but powerful feature of the Business Central UI: the ability to create collapsible tree controls in list pages using AL. While certain data — like a chart of accounts — truly benefits from this hierarchical presentation, it’s not a feature that’s commonly used, even in the base application. Let’s walk through how it works.

Understanding Indentation in Business Central

Before diving into tree controls, it’s important to understand that Microsoft uses the term “indentation” in two different ways in Business Central:

  1. Visual indentation only — Data is indented to show hierarchy, but nothing is collapsible. This is what you see on the standard Chart of Accounts page. The Name column is indented based on the account’s level, but you can’t collapse or expand anything.
  2. Tree control (collapsible indentation) — Data is indented and collapsible, allowing users to expand and collapse parent nodes to show or hide child entries. This is the true “tree control.”

The Indentation Field

The foundation of any tree control is the Indentation field on the source table. On the G/L Account table, this field contains a numeric value indicating the hierarchy level:

  • Level 0 — Top-level items (e.g., “Assets,” “Total Assets,” “Liabilities and Equity”)
  • Level 1 — First-level children (e.g., “Current Assets”)
  • Level 2 — Second-level children (e.g., “Cash and Deposits”)
  • Level 3 — Third-level children (individual accounts)

This number simply tells the system how far in something should be indented. The data must be sorted by the primary key for the hierarchy to make sense — you cannot re-sort a collapsible list because the parent-child relationships depend on the record order.

Building the Tree Control

Let’s look at the key repeater properties that make a tree control work. Here is the complete page definition:

page 50142 "Tree test"
{
    PageType = list;
    SourceTable = "G/L Account";
    Editable = false;
    layout
    {
        area(Content)
        {
            repeater(rep)
            {
                IndentationColumn = Rec.Indentation;
                IndentationControls = Name;
                ShowAsTree = true;
                TreeInitialState = CollapseAll;
                field(Indentation; Rec.Indentation)
                {
                    ApplicationArea = all;
                    Visible = false;
                }
                field(Name; Rec.Name)
                {
                    ToolTip = 'Specifies the name of the cash account.';
                    ApplicationArea = All;
                }
                field("No."; Rec."No.")
                {
                    ToolTip = 'Specifies the number of the involved entry or record, according to the specified number series.';
                    ApplicationArea = All;
                }
                field(Balance; Rec.Balance)
                {
                    ToolTip = 'Specifies the balance of the cash account.';
                    ApplicationArea = All;
                }
                field("Net Change"; Rec."Net Change")
                {
                    ToolTip = 'Specifies the net change in the account balance during the time period in the Date Filter field.';
                    ApplicationArea = All;
                }
            }
        }
    }
}

The Four Key Repeater Properties

There are four properties on the repeater that control the tree behavior:

  • IndentationColumn — Specifies which field on the source table determines the indentation level. Here it’s set to Rec.Indentation. This field must be part of the dataset (included as a field in the repeater), but it doesn’t need to be visible.
  • IndentationControls — Specifies which control (column) on the page displays the indentation visually. Here it’s set to Name, which is the control name of the Name field. Note the distinction: IndentationColumn references the table field, while IndentationControls references the page control.
  • ShowAsTree — Set to true to enable collapsible behavior. Without this, you only get visual indentation with no ability to collapse or expand.
  • TreeInitialState — Controls whether the tree starts fully collapsed or fully expanded. Options are CollapseAll or ExpandAll.

The Indentation Field Must Be in the Dataset

A critical detail: the Indentation field must be included as a field in the repeater for the tree to work. However, you can set Visible = false on it so that it doesn’t show as a column to the user. It just needs to be part of the dataset that the page retrieves.

How It Behaves at Runtime

With TreeInitialState = CollapseAll, when the page opens, only the level 0 items are visible. Users can then:

  • Click the expand arrow on a row to reveal its children
  • Continue expanding deeper levels to see more detail
  • Use the “expand all” or “collapse all” controls at the top of the list to toggle everything at once

The indentation is applied to the first visible column in the repeater. If you want the Name column to show the tree structure, make sure it appears first in your field list (or at least before other columns that shouldn’t be indented).

Important Limitations

  • No sorting allowed — As soon as a list is displayed as a tree, sorting is disabled. The hierarchy depends entirely on the record order defined by the primary key. Changing the sort order would break the parent-child relationships.
  • No programmatic control over collapse state — There’s no way in AL to programmatically control which specific nodes are collapsed or expanded. You can only set the initial state for the entire tree.
  • The indentation only works within the current sort order — The IndentationColumn values only make sense when records are displayed in their natural primary key order.

Conclusion

The tree control in Business Central is a powerful but underutilized feature. By setting just four properties on a repeater — IndentationColumn, IndentationControls, ShowAsTree, and TreeInitialState — you can transform a flat list into a collapsible hierarchical view. This works beautifully for data that naturally has parent-child relationships, such as charts of accounts, BOMs, schedules, or any dataset with an indentation field. While it has limitations around sorting and programmatic control, it provides a clean and intuitive way to present hierarchical data that customers appreciate. Give it a try with your own data structures!