Skip to main content

Notifications

Announcements

No record found.

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 1,707

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.

  • GER_Nico Profile Picture
    GER_Nico 115 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
    Inkey Solutions 1,707 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
    GER_Nico 115 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
    Inkey Solutions 1,707 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
    Nitin Verma 21,091 Super User 2024 Season 1 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
    Inkey Solutions 1,707 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
    Nitin Verma 21,091 Super User 2024 Season 1 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans