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…
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.
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:
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!