Event Handler Methods in Dynamics 365 for Operations (AX7)
In Dynamics 365 for Operations (AX7) the preferred mechanism for customizations to existing objects is to use event handlers to react to various events rather than overriding methods on tables, forms, and classes. For example, to change what happens when a button is clicked in AX 2012 you override the clicked method and put code either before or after the super() call. In Dynamics 365 for Operations (AX7) you can react to the OnClicked event by copying the event handler method for the event and pasting the method into a class. Below is an example of an event handler method that reacts to the OnClicked event of a button on a form.
public static void ArgsExampleButton_OnClicked(FormControl sender, FormControlEventArgs e) { Args args = new Args(); Form formToCall = new Form('ArgsDemo_Callee'); FormButtonControl callerButton = sender as FormButtonControl; //Retrieves the button that we're reacting to FormRun form = callerButton.formRun(); //Gets the running HcmWorker form //Get the HcmWorker that was selected in the HcmWorker form FormDataSource hcmWorker_ds = form.dataSource(formDataSourceStr(HcmWorker, HcmWorker)) as FormDataSource; HcmWorker hcmWorker = hcmWorker_ds.cursor(); //Set up args with all of the information you've retrieved args.caller(form); args.object(formToCall ); args.record(hcmWorker); form = ClassFactory.formRunClass(args); form.init(); form.run(); form.wait(); }
You can learn more about event handler methods and more in our online Dynamics 365 for Operations Development Workshop, beginning July 10! Detailed agenda and registration here.