Event Method Sequences when a Form is Closed
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
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.
Close the Form by Using the Cancel Button
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.
Close the Form by Using the Close Button
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.
Close the Form by Using the OK Button
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.
See also
Event Method Sequences in Form Scenarios
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.