Event Handler Methods in Dynamics 365 for Operations (AX7)

By Becky Newell | December 20, 2016

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.object(formToCall );

        form = ClassFactory.formRunClass(args);

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.

Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!