Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Dynamically make page fields visible based on the value of another field

Posted on by 2,983

Quick question, why this doesn't work?? No matter how many times I change MyOption field's value, FieldH,V and F are never visible. BC 21.1 environment.

pageextension 50004 "Custom Item card" extends "Item Card"
{
    layout
    {
        addafter(VariantMandatoryDefaultNo)
        {
           
            field(MyOption; Rec.MyOption)  //This is an Option type field in my Item table
            {
                ApplicationArea = Basic, Suite;
            }
            field("FieldH"; Rec."FieldH")
            {
                ApplicationArea = Basic, Suite;
                Visible = Rec.MyOption= Rec.MyOption::"1 Eje"; //Tried with a specific Option value, but still not working
            }
            field("FieldV"; Rec."FieldV")
            {
                ApplicationArea = Basic, Suite;
                Visible = Rec.MyOption> 1;    //This is what I actually need to achieve
            }
            field("FieldF"; Rec."FieldF")
            {
                ApplicationArea = Basic, Suite;
                Visible = Rec.MyOption> 2;
            }
        }
    }
}
Curious fact, Editable = Rec.MyOption> 1; works perfectly, so browser wise, it shouldn't be a problem, as I guess all this has JS on code in the background
  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Dynamically make page fields visible based on the value of another field

    Hi

    you must value your control variables in the OnAfterGetRecord() trigger of the page

    DAniele

  • antmas Profile Picture
    antmas 60 on at
    RE: Dynamically make page fields visible based on the value of another field

    ZHU, this post has helped me numerous times, so thanks very much!

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,565 Super User 2024 Season 2 on at
    RE: Dynamically make page fields visible based on the value of another field

    Hi, hope the following helps.

    Dynamic Visibility of Controls (Hide and show fields dynamically)

    https://yzhums.com/14752/

    Thanks.

    ZHU

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Dynamically make page fields visible based on the value of another field

    Hi,

    You can try as per below

    pageextension 50004 "Custom Item card" extends "Item Card"
    {
        layout
        {
            addafter(VariantMandatoryDefaultNo)
            {

                field(MyOption; Rec.MyOption)  //This is an Option type field in my Item table
                {
                    ApplicationArea = Basic, Suite;
                }
                field("FieldH"; Rec."FieldH")
                {
                    ApplicationArea = Basic, Suite;
                    Visible = VisibleControl; //Tried with a specific Option value, but still not working
                }
                field("FieldV"; Rec."FieldV")
                {
                    ApplicationArea = Basic, Suite;
                    Visible = VisibleControl2;    //This is what I actually need to achieve
                }
                field("FieldF"; Rec."FieldF")
                {
                    ApplicationArea = Basic, Suite;
                    Visible = VisibleControl3;
                }
            }
        }

        trigger OnAfterGetRecord()
        begin
            VisibleControl2 := Rec.MyOption > 1;
            VisibleControl := Rec.MyOption = Rec.MyOption::"1 Eje";
            VisibleControl3 :=  Rec.MyOption > 2;
        end;

        var
            VisibleControl: Boolean;
            VisibleControl2: Boolean;
            VisibleControl3: Boolean;
    }
  • Mayank Jangid Profile Picture
    Mayank Jangid 60 on at
    RE: Dynamically make page fields visible based on the value of another field

    Yes, you have to put each and every field in a separate group. Because this is the only way to Dynamically Hide and Unhide the field.

  • Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: Dynamically make page fields visible based on the value of another field

    Actually visibility conditions are different for each field. If this is the case, I will need to create one group per field. Was wondering if there was any way to avoid that.

  • Mayank Jangid Profile Picture
    Mayank Jangid 60 on at
    RE: Dynamically make page fields visible based on the value of another field

    Hello Ghetz,

    You need to put all the fields inside the group to which you want to hide or unhide and give visibility property to the group.  

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans