Protected Variables

APPLIES TO: Business Central 2019 release wave 2 and later

The protected keyword can be used to make variables accessible between tables and table extensions and between pages and page extensions. If you want to only expose some variables as protected, you must create two sections of var declarations. See the syntax below.

Syntax

protected var
        myInt: Integer; // protected var

var
        myLocalInt: Integer; // local var

Example

The example below illustrates how to declare and use a protected variable.

page 500100 MyPage
{
    SourceTable = Customer;
    PageType = Card;

    layout
    {
        area(Content)
        {
            group(General)
            {
                field(Name; Name)
                {
                    ApplicationArea = All;
                }
            }
            group(Advanced)
            {
                Visible = ShowBalance;

                field(Balance; Balance)
                {
                    ApplicationArea = All;
                }
            }
        }
    }

    protected var
        [InDataSet]
        ShowBalance: Boolean;
}

pageextension 500101 MyPageExt extends MyPage
{
    layout
    {
        addlast(Content)
        {
            group(MoreBalance)
            {
                Visible = ShowBalance; // ShowBalance from MyPage

                field("Balance (LCY)"; "Balance (LCY)")
                {
                    ApplicationArea = All;
                }
            }
        }

    }

    actions
    {
        addlast(Navigation)
        {
            action(ToggleBalance)
            {
                ApplicationArea = All;
                trigger OnAction()
                begin
                    ShowBalance := not ShowBalance; // Toggle ShowBalance from MyPage.
                end;
            }
        }
    }
}

See Also

AL Method Reference
Properties
Access Property
Extensible Property