You can define a function that is triggered by a form or control event or modify an existing function.
To define or modify a form or control trigger
Open the form in the Form Designer.
Select the form or the control (or menu item) and click View and then click C/AL Code (F9) to open the C/AL Editor.
In the editor, you have access to the triggers that apply to the object that you selected. Enter C/AL code in the triggers that you want to use, or modify the existing triggers.
Click Tools and then click Compile (F11) to test and compile the form. This will include the code that you added or modified.