Dynamically hide and show controls on Card Page

14 Jan

Do you recognize that? That moment you think ‘I should have known that earlier’. Well, for me this was such a moment, as I realized that something that allegedly wasn’t possible since we said goodbye to the Classic Client, proved to be possible but in a different way…

The problem

Dynamically hide and show a control on a card. Ever used before in the Classic Client? I did, but when I tried to achieve the same with the Windows Client (or RTC or whatever you may name it) it didn’t work the same way as before. Controls on a page have the Visible property, and you can set that property to a variable or expression instead of TRUE/FALSE. But it appears that the control only reacts to the Visible property during the OnOpenPage trigger. If you change the variable value in the OnAfterGetRecord trigger or with code behind an Action, the visibility of the control doesn’t change. Other properties like Enabled and Editable do dynamically react, but Visible doesn’t. So it seems that we only can hide or show a field during startup of the Page.

The solution

But then I came across Page 360 (Document Sending Profile) in NAV 2016, and I discovered a simple and effective solution to achieve the behavior I was looking for.

In my last Web Services example about barcodes, I have used this solution to dynamically hide and show controls. When changing the bar code type to QR, which isn’t really a barcode, the Page reacts with displaying different options.

Compare these two screen prints of the same barcode.


Changed to type QR:


In detail

It is as simple as putting the fields in a group and set the Visible property of the group to the expression you want to use. The expression can either be a Boolean variable, field or C/AL expression that returns TRUE or FALSE.

As you can see here, there are two groups:


And here are the properties of the first group:


And the second group:


Well, there’s not much more to add to it. Go and take a look at Page 360 in NAV 2016 which uses this solution. Even in a nested scenario.

Just one remark: the behavior of Page 360 is in my opinion a little bit too messy. Dynamically displaying controls can result in repositioning of other controls on the screen. I don’t considered this as very user friendly. So use this carefully and make sure that users do not get unexpected results because controls are moved to a different place to squeeze in a new control. It must be clear to user what just happened.

Oh, before I forget, this also works in the Web Client!

11 thoughts on “Dynamically hide and show controls on Card Page

  1. Hmm, as I know this works also in 2009 RTC. You have to set an new variable and set the property “IncludeInDataSet” to Yes. After that you can set the new variable in the onaftergetrecord or onaftergetcurrentrecord to true or false. You can also set the variable in a validate trigger of the page.

    Now, you have to assign the variable in the visible property of the field and you are down.

    Did you know that?

  2. Great job! This worked perfectly for me. I had one small issue… I tried to set the Visibility of the Group to COMPANYNAME = ‘someName’. The compiler didn’t like that, so all I did was use a global variable to hold the value returned from COMPANYNAME, and it worked just fine. Thanks.

  3. Please, can you help me.
    What I need to do, if I want this functionality on the web client?
    Is this supported on web client?


  4. Pingback: Web Client dynamic visibility of fields and page actions - The NAV Blog - D365 Business Central/NAV Users - DUG

  5. Pingback: Web Client dynamic visibility of fields and page actions - Robberse - Dynamics 365 Business Central/NAV User Group - Dynamics User Group

  6. Pingback: Web Client dynamic visibility of fields and page actions - Microsoft Dynamics NAV Community

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.