web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to Hide and Show fields dynamically in the AL language? [Business Central]

(0) ShareShare
ReportReport
Posted on by 2,075

Hi All,

I want to Hide some fields based on some condition. for example, I have one field type of lookup and in that I have a lookup table, and I am selecting one option from there suppose 'Tangible' so based on Tangible option I want to hide some other fields and show some fields. I tried below code, but it didn't work.

>>Below is screen print for the Lookup field:

pastedimage1675233019938v1.png

>>Here hideshow is variable of type boolean.

// local procedure hideshowfield(): Boolean
    // begin
    //     hideshow := true;
    //     if Rec."FA Class Code" = 'HOUSE' then begin
    //         hideshow := false;
    //         exit(hideshow);
    //     end else begin
    //         hideshow := true;
    //         exit(hideshow);
    //     end;
    // end;

 

pastedimage1675228893802v2.png

 modify("FA Class Code")
        {
            Caption = 'Asset Type';
            trigger OnAfterValidate()
            begin
                //hideshowfield();
            end;
        }

pastedimage1675228948247v3.png

field("Description 2"; Rec."Description 2")
            {
                ApplicationArea = all;
                //Visible = hideshow;
            }

Can anyone give me a suggestion what is missing here? or any other way to achieve this?

Thank You.

I have the same question (0)
  • GER_Nico Profile Picture
    117 on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    That's nice to hear. Could you please verify my answer as the correct answer. Unfortunately, you chose yours instead.

  • Verified answer
    Inkey Solutions Profile Picture
    2,075 on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    Thank You GER_Nico , this solution is work for me.

    Thank you so much once again.

  • GER_Nico Profile Picture
    117 on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    Hello Inkey Solutions,

    Unfortunately, it is not possible to show and hide fields dynamically. But where it works is with groups. I have no idea why it works for groups and not for fields. So you have to put the fields you want to show and hide in a group.

    You can try it yourself with the following code:

    page 50153 "TestPage"
    {
        ApplicationArea = All;
        Caption = 'TestPage';
        PageType = Card;
        
        layout
        {
            area(content)
            {
                group(General)
                {
                    field(OptionField; OptionField)
                    {
                        trigger OnValidate()
                        begin
                            if OptionField = OptionField::Option3 then
                                isVisible := false
                            else
                                isVisible := true;
                        end;
                    }
                    field(TextField1; TextField1){
                        Visible = isVisible;
                    }
                    group("HideGroup")
                    {
                        ShowCaption = false;
                        Visible = isVisible;
                        field(TextField2; TextField2){}
                    }
                }
            }
        }
    
        trigger OnOpenPage()
        begin
            isVisible := true;
        end;
    
        var
            OptionField: Option Option1, Option2, Option3;
            TextField1, TextField2: Text[100];
            [InDataSet]
            isVisible: Boolean;
    }

    [View:/cfs-file/__key/communityserver-discussions-components-files/758/TestPage-_2D00_-Dynamics-365-Business-Central-_1320_-Microsoft_5F00_-Edge-2023_2D00_02_2D00_01-08_2D00_38_2D00_13-_2800_online_2D00_video_2D00_cutter.com_2900_.mp4:320:240

    Warm greetings
    Nico

  • Inkey Solutions Profile Picture
    2,075 on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    Nitin Verma I already did this, but nothing work for me.

    Thank you.

  • Suggested answer
    Nitin Verma Profile Picture
    21,627 Moderator on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    Hi,

    Please declare your variable like below

    var

    [InDataSet]

    hideshow :boolean;

    and use that variable wherever you want.

  • Inkey Solutions Profile Picture
    2,075 on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    Hi, Nitin Verma

    Edited the post, please look into it.

  • Suggested answer
    Nitin Verma Profile Picture
    21,627 Moderator on at
    RE: How to Hide and Show fields dynamically in the AL language? [Business Central]

    Put your code in Text format not in Image.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sumit Singh Profile Picture

Sumit Singh 3,055

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 2,682 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 2,209 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans