Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

dynamic visibility using grids not working

(0) ShareShare
ReportReport
Posted on by 36
Hello everyone.
 
Since a few months ago there was a change which “broke” the way some code worked for years.
When you have groups within a grid that also have visibility using variables, it does not display correctly in BC.

I created a code to simplify the situation by following this post by Yun Zhu
https://yzhums.com/14752/
But modified. What you want to achieve is the following:
 
 
A “Type” field that depending on what is selected, either the two “Car” fields or the two “Motorcycle” fields or all 4 are displayed.
This does not work when the field “Type” initializes variables in false in the trigger OnOpenPage, being shown this way:
(no fields are displayed, just a small blank space).

I leave the code that can be deployed and easily reproduced by creating a new client, in the same way as the original post.
I reiterate that this worked for years until a few months ago. 
If the way to write this code is incorrect, what would be the way to achieve the same goal?
 
Thanks
 
tableextension 50111 ZYCustomerExt extends Customer
{
    fields
    {
        field(50100; "Type"; Option)
        {
            Caption = 'Type';
            OptionMembers = " ","Car","Motorcycle","All";
            DataClassification = CustomerContent;
        }
        field(50101; "Car Code 1"; Code[20])
        {
            Caption = 'Car Code 1';
            DataClassification = CustomerContent;
        }
        field(50102; "Car Description 1"; Text[50])
        {
            Caption = 'Car Description 1';
            DataClassification = CustomerContent;
        }
        field(50103; "Motorcycle Code 1"; Code[20])
        {
            Caption = 'Motorcycle Code 1';
            DataClassification = CustomerContent;
        }
        field(50104; "Motorcycle Description 1"; Text[50])
        {
            Caption = 'Motorcycle Description 1';
            DataClassification = CustomerContent;
        }
    }
}
pageextension 50111 ZYCustomerCardExt extends "Customer Card"
{
    layout
    {
        addafter(Name)
        {
            field(Type; Rec.Type)
            {
                ApplicationArea = All;
                trigger OnValidate()
                begin
                    InitializeVariables();
                end;
            }
            group(CategoriesGroup)
            {
                Visible = Car1Visible or Motorcycle1Visible;
                ShowCaption = false;
                grid(grid)
                {
                    group(Names)
                    {
                        ShowCaption = false;
                        group(CarCode)
                        {
                            Visible = Car1Visible;
                            ShowCaption = false;
                            field("Car Code"; Rec."Car Code 1")
                            {
                                ApplicationArea = All;
                            }
                        }
                        group(MotorcycleCode)
                        {
                            Visible = Motorcycle1Visible;
                            ShowCaption = false;
                            field("Motorcycle Code 1"; Rec."Motorcycle Code 1")
                            {
                                ApplicationArea = All;
                            }
                        }
                    }

                    group(Descriptions)
                    {
                        ShowCaption = false;
                        group(CarDescription)
                        {
                            Visible = Car1Visible;
                            ShowCaption = false;
                            field("Car Description"; Rec."Car Description 1")
                            {
                                ApplicationArea = All;
                            }
                        }
                        group(MotorcycleDescription)
                        {
                            Visible = Motorcycle1Visible;
                            ShowCaption = false;
                            field("Motorcycle Description 1"; Rec."Motorcycle Description 1")
                            {
                                ApplicationArea = All;
                            }
                        }
                    }
                }
            }
        }
    }
    trigger OnOpenPage();
    begin
        InitializeVariables();
    end;

    var
        Car1Visible, Motorcycle1Visible : Boolean;


    local procedure InitializeVariables()
    begin
        case Rec.Type of
            Rec.Type::" ":
                SetFieldsVisible(false, false);
            Rec.Type::Car:
                SetFieldsVisible(true, false);
            Rec.Type::Motorcycle:
                SetFieldsVisible(false, true);
            Rec.Type::All:
                SetFieldsVisible(true, true);
        end;
    end;

    local procedure SetFieldsVisible(Code1Visible: Boolean; Code2Visible: Boolean)
    begin
        Car1Visible := Code1Visible;
        Motorcycle1Visible := Code2Visible;
    end;
}
 
  • Verified answer
    SantiagoM Profile Picture
    SantiagoM 36 on at
    dynamic visibility using grids not working
    Ok. So, just to put it in writing, after talking to Microsoft with this example and the Yammer release mentioned by Alexander (Thanks for mentioning it) they have confirmed to me that it is a bug that will be fixed for version 26.0.
    Thanks for your replies
  • Alexander Drogin Profile Picture
    Alexander Drogin 170 on at
    dynamic visibility using grids not working
    Pardon, it was my misunderstanding of the problem then. Looks like this is indeed a bug in grid rendering in the client v25.1, there is a Yammer thread on this issue.
  • Ramiz Profile Picture
    Ramiz 463 on at
    dynamic visibility using grids not working
    Hi,

    I tested it and same issue. I think its rendering issue. After changing the value from blank to any other value, I dont see the grid but if I refresh the page I see the grid as expected.
  • SantiagoM Profile Picture
    SantiagoM 36 on at
    dynamic visibility using grids not working
    Hello Alexander, thank you for your reply
     
    what you say makes sense, but I have tested it and it doesn't work, it even works worse than before.
     
    I have uploaded a video to try to explain the situation better (it is being uploaded).
    The problem is not so much that you get the value of the DB late, but that depending on how the global variables are initialized, this works or not.
    That is to say, if the variables are initialized in false, then when changing the field “Type” it doesn't work. But if even one variable is initialized to true, then the dynamic visibility works properly as it should.
  • Suggested answer
    Alexander Drogin Profile Picture
    Alexander Drogin 170 on at
    dynamic visibility using grids not working
    My feeling is that it's not a change from Business Central that "broke" this functionality. I don't know how it worked previously, but I'll try to give an educated guess on what is happening, based on the code example.
    When the page opens, the Type field shows the value "All", which is retrieved from the Customer record displayed in the page. But the OnOpenPage trigger is executed before any record is read from the DB table. So it makes sense that at this point the field is initialized to the default value, which is blank.
    Therefore the fields are rendered based on the default blank option value, and only after that the record is loaded into the page with the actual field value "All".
    I would say that the correct way to update these fields would be to move the InitializeVariables call to the OnAfterGetCurrRecord trigger.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,540 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans