usage of dynamic visible property in Business Central dynamics

107 Views Asked by At

Assume there is component address table and it contains two address - component address 1 and component address 2. Component address 1 is parent of component address 2. Each Component address contains object monitoring lines. So now when we call the component address 2 - it shows object monitoring lines of component address 2 and the parent Component address 1. In object monitoring line page the fields (columns) "Type" and "Number" should be shown for Component Address 2, but not for Component address 1.

I am able to show or hide fields, but i didn't find a way how to dynamically show the fields.

1

There are 1 best solutions below

0
ChristianBraeunlich On

To dynamically show fields, we need to use groups. So whenever you want to dynamically show actions or fields, wrap a group around them.

You can follow these steps:

  1. Define a global page variable of data type Boolean.
  2. Create and wrap a group around the action/field you want to dynamically show.
  3. Use the global variable in the Visible property of the group that includes the action/field on the page.
  4. Set the ShowCaption property to false as we do not want to show the caption of this group.
  5. Optional: set the value of the variable to true in the OnInit trigger to show the action/field by default.

Here is an example:

page 50100 MyPage
{
    PageType = Card;
    ApplicationArea = All;
    UsageCategory = Administration;

    layout
    {
        area(Content)
        {
            group(MyGroup)
            {
                Visible = MyActionIsVisible;
                ShowCaption = false;

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

    actions
    {
        area(Processing)
        {
            action(ActionName)
            {
                ApplicationArea = All;

                trigger OnAction()
                begin
                    MyActionIsVisible := not MyActionIsVisible; // toggle show
                end;
            }
        }
    }

    trigger OnInit()
    begin
        MyActionIsVisible := true; // show field by default
    end;

    var
        MyField: Text[250];
        MyActionIsVisible: Boolean;

}