Something interesting about Group containers in Pages in Dynamics NAV 2009 came to my attention, and I thought why not share it?
When designing page objects in NAV 2009, you can use Group containers to group fields together. This way you can somehow control where fields should be shown on a page and you can group them together.
But a Group container also has some very interesting properties like for example: Visible and Enabled. Ok, that's not so special you might be thinking…
è But heres the clue: as from NAV 2009 these properties can be set as the result of an expression.
What does this mean?
You are now able to "play" with the visible and enabled property for a group container via C/AL code. This way you can enable or disable a group of fields in 1 go.
The following is valid for the Page properties:
- Visible
- Enabled
- Editable
For example in the Customer Card Page:
Add a Group container around the fields Address and Address2:
Create a Global Boolean variable BAddressgroupVisible and assign it into the Visible property of the Group:
In the C/AL code, for example in the OnAfterGetRecord trigger add the following code:
Result: the fields are shown:
Now assign FALSE to the Boolean:
Result: the fields are not shown:
Very interesting, isn't it?
As you can see, you instead of using a Boolean variable, you could let it depend on a field from the table. As a consequence the fields will then be shown for some records and not for others.
There's a little trick you need to apply if you use a variable. In the properties of the variable you need to put the property IncludeInDataset to Yes:
If you don't do that then you will get the following error message at runtime:
Remark:
- The IncludeInDataset property defines that the variable will be added to the DataSet of the Page.
- The Visible and Enabled properties can only be set from fields contained in the DataSet of the Page.
I was playing around with this too, but what I was a bit "concerned" about was the layout of the fields if the group is a fasttab. If you set the boolean variable to TRUE OnInit, then the fields in the fasttab group are split correctly. However if you start with FALSE and then show the group via an Action, then the fields are only in a single column, as opposed to split in two as is standard. This might not be an issue when you are setting show/hide via a db setting, but I think the single column issue might be a bug of sorts.
Posted by: Bruce Heath | 04/05/2009 at 15:40