handler is code that runs before the associated method runs or after the associated
method has finished running. The event handler itself is also a class method, and
it can be written in either X++ or managed code.
To create an Event Handler in managed code, perform the following procedure.
This procedure assumes the method that will have its events handled has already
been created in the AOT, in this case, SalesFormLetter.run():
1. Open Visual Studio.
2. Create a Managed Code project.
3. Rename the class to a meaningful name. In the example the class will
be named MyPreEventHandler.
4. Save the project.
5. Build the class by clicking Build and then Build
MyPreEventHandler.
6. Right-click on the project in the Solution Explorer and select Add<Project Name> to AOT.
7. If the Application Explorer is not visible, open it.
8. In the code editor, open the MyPreEventHandler class and place
the cursor somewhere inside the class.
9. In the Application Explorer, locate the SalesFormLetter class.
Expand it and locate the run method.
10. Right-click the run method and select Add pre event handler.
11. Notice that an event handler method is created, as shown.
1 2 3 4 5 6 7 | // Do not change the name of the event handler method. If you rename the method, the event handler will not work. [Microsoft.Dynamics.AX.ManagedInterop.XppClassDefiningEvent Attribute(@"\Classes\SalesFormLetter")] static public void PreRun(XppPrePostArgs args) { } |
The method created is empty, and ready for the pre-event code to be added. Do
not change the name of the method, or the event handler will not work.
Best Regards,
Hossein Karimi
No comments:
Post a Comment