When you write a function for a form, you may need user input for the function, such as a filter or sorting key. In this case, we recommend that you use the RunObject property of the menu item and then set a record as a parameter by reference on the codeunit instead of writing C/AL code in the OnPush trigger of the command button or menu item. The benefit of this approach is that you avoid having functionality code on the form.


An example of a function that uses user input is form 251, General Journal Batches, in the CRONUS International Ltd. demo database. On this form, a user can set a filter on the name of the batch before running the Post function so that only the batches in the filter are posted. The Post function on the form is designed such that in Menu Designer for the Post menu item, the Action field is set to RunObject and the RunObject field is set to Codeunit Gen. Jnl.-B Post. This codeunit has a record of the Gen. Journal Batch table as a parameter of its OnRun function. The parameter is passed by reference. Because the parameter is passed by reference, any filters that the user set on form 251 are respected in the OnRun function of the codeunit.

Additional Filter and Sort Options

If you want to provide the user with more filtering and sorting possibilities or other option settings before starting a function, then use one of the following:

See Also