Business requirement: Change the behaviour of a form without user interaction
Upon opening a form, you would like to change its behaviour without interaction of the end user, for example, you want to preset some filters, hide some columns, … depending on the context it is called. Off course you want to avoid to create a second, third, … form for this requirement.
This post describes how this can be achived easily by merely creating a new Menu Item and adding a little piece of code in the form involved.
As example in this post the Project Item Requirements form will be opened with a different filter. Depending on the context, all item requirements will be shown or only the active requirements.
Solution: Use the EnumTypeParameter property on a Menu Item
- Drag and drop the ProjSalesItemReq form to the Display node in the AOT as such creating a new Display Menu Item.
- Set the EnumTypeParameter property of the newly created Menu Item to NoYes and the EnumParameter property to Yes.
- Add a variable to the init method of the form ProjSalesItemReq, which will be used to store the value according to with which menu item the ProjSalesItemReq form will be called.
NoYes showAll;
- Add following code snippet to the init method of the form ProjSalesItemReq, to set the value of the filter if the form is called with the newly created Menu Item.
…
if (element.args().parmEnumType())
{
showAll = element.args().parmEnum();
if (showAll)
{
ctrlActiveAll.selection(ProjActiveAll::All);
}
}
… - Add the newly created Menu Item to the ProjTable form.
If you open the Item Requirements form with the standard Dynamics AX MenuItemButton, the filter will be set to Active, showing only the active item requirements.
If you open the Item Requirements form with the newly created MenuItemButton, the filter will be set to All, showing all item requirements for the selected Project.
Post a Comment