User actions on a form are input through mouse pointers and keyboards. These actions cause events that are recognized by Microsoft Dynamics AX. The recognized events include the following:
The system reacts to each event by executing several event methods. The user is often unaware that these methods are being executed.
Customize the Responses to User Events
Use the Application Object Tree (AOT) to override the event methods and customize the response to form events.
Expand the Forms node to see its Methods subnode.
Expand the Methods node to see a subnode for each method that is currently overridden.
Right-click the Methods node, and then select Override Method to see a list of methods that have not yet been overridden.
Expand other nodes under Forms to see additional Methods nodes.
Information about the sequence of event method execution is useful when you are determining the correct method to override. For example, you could write code to log the inserts that the user causes when they enter data into a grid control. This code could be placed in various event methods. You could override the insert event method on an underlying table. By knowing the aosValidateInsert method is executed immediately after the insert method, you might instead choose to log the aosValidateInsert method. Overriding aosValidateInsert might provide log information that has the results of security checks.
In this example, the user opens a form that contains a grid control, which is bound to a data source.
The executed events are distributed across two threads. The timing of event method execution between threads can vary.
The following table shows the sequence that event methods are executed in when a user opens a form.
Most forms in Microsoft Dynamics AX are closed when a user clicks the Close button (the standard button in the upper-right corner of most windows). Some forms can be closed by clicking either an OK or a Cancel button. When the form is closed, event methods are executed.
When a user closes a form by clicking the Cancel button, event methods are executed in the following sequence:
closeCancel on the form.
canClose on the form.
close on the form.
Note
The FormRun class has the closed method and the closedCancel method. These event methods are not executed when the Cancel button is clicked.
When a form is closed with the closeCancel event method, the user's changes are not saved.
Scenario
This scenario uses a form that contains one CheckBox control as its only control. Assume that the CheckBox control is bound to a form's data source and that the control can update the data source.
When a user closes a form by clicking the Close button, event methods are executed in the sequence shown in the following lists. These lists are based on the previous scenario.
Following is the sequence of event methods when the form is closed—without the user clicking the check box.
canClose on the form.
leave on the check box.
leave on the check box.
leave on the data source.
leaveValidate on the data source.
leave on the check box.
leave on the check box.
close on the form.
saveUserSetting on the form.
Following is the sequence of event methods when the form is closed—after the user has clicked a check box.
canClose on the form.
leave on the check box.
leave on the check box.
validateWrite on the data source.
Write on the data source.
update on the table.
leaveRecord on the data source.
leave on the data source.
leaveRecord on the data source.
leave on the check box.
leave on the check box.
close on the form.
saveUserSetting on the form.
Some forms can be closed by clicking an OK button. This leads to almost the same event method sequence as shown in the Close the Form by Using the Close Button section. The only difference is that clicking the OK button causes the Form.closeOK event method to be executed first.
Event methods are executed when the value of a control changes. The exact sequence of event methods varies for different controls.
Check Box Scenario
The example scenario uses a simple form that has a check box control. The check box is bound to a field in a data source.
A check box is a control that has a value property. In contrast, a grid control contains fields that each display a value, but the grid itself does not have a value property.
Click to Change the Value in a Check Box
The following sequence of event methods is executed when the check box is either selected or cleared by a user.
validate on the check box.
modified on the check box.
validateField on the table.
Remove Focus from a Check Box
The following event method is the only one executed when focus is removed from the check box:
An event method sequence is executed when focus is removed from a record. The sequence includes the leaveRecord method. Form controls that simultaneously display multiple records have the leaveRecord event method.
Grid Scenario
This scenario has a form that contains a grid control, which is bound to a data source. The form is open, and the grid is populated with data. Focus is on the first line of the grid.
Move Focus from one Record to Another
Without changing any data, the user clicks a different grid line to move focus to that line. The following event method sequence is executed when data in the first line is unchanged.
leave on the data source.
leaveRecord on the data source.
A longer event method sequence occurs when grid line data changes before focus is moved from that grid line.
modifiedField on the table.
update on the table.
aosValidateUpdate on the table.
leaveRecord on the data source.
leave on the data source.
leaveRecord on the data source.
An event method sequence is executed when a record is deleted from a grid control. The grid control is on a form.
Grid Scenario
This scenario has a form that contains a grid control, which is bound to a data source. The data source is associated with a table. The form is open and the grid is populated. Focus is on the first line of the grid.
The user presses ALT+F9 to delete the record, and then clicks Yes to confirm. The following event methods are executed in response to that event.
validateDelete on the table.
delete on the table.
aosValidateDelete on the table.
leaveRecord on the data source.
Event methods are executed when a form is used to create a new record. The details can vary, depending on the type of controls present on the form.
Grid Scenario
In this scenario, a form contains one grid control. A data source is bound to the grid control. The data source is associated with two fields from a table.
A user opens the form, and then the grid is populated with data. The first line in the grid has focus.
A User Creates a Record
A user enters a new record by using a grid control on a form. They begin by pressing the shortcut keys CTRL+N. This creates a new, empty line in the grid and gives focus to the new line. The following list shows the sequence of event method executions that occurs when the user continues with the steps needed to create a record in the database.
leaveRecord on the data source.
The user enters data into the first empty cell, and then presses TAB.
validateField on the table.
modifiedField on the table.
The user now enters data into the second empty cell. They click a grid line that is already populated to take focus from the new line.
validateField on the table.
modifiedField on the table.
validateWrite on the table.
insert on the table.
aosValidateInsert on the table.
leaveRecord on the data source.
leave on the data source.
leaveRecord on the data source.