How to use Event Handler in Microsoft Dynamics AX 2012
1)Open your new developer work space and go to AOT then classes node.
2)Right click on Classes node and click on New Class as shown below.
3) By default system will give a name to it. Here in my case it’s Class1. Right click on newly created class and click on Rename shown below.
4) After clicking Rename, give a name called CustTableEventHandler to it. Here I am going to develop an event to be applied on CustTable so that is the reason why I decided this name (CustTableEventHandler). After renaming this class, it looks as shown below.
5) Right click on class CustTableEventHandler then New then Pre- or post-event handler as shown below.
6) Once you click on this, system gives you a method as shown below.
7) Customize the method as shown below.
8) Here args is providing current record to custTable instance and info is displaying the current customer account. The code snippet is below.
public static void custCreateInfo(XppPrePostArgs _args)
{
CustTable custTable;
custTable = _args.getThis();
info(strFmt("Customer account %1 has been created", custTable.AccountNum));
}
This method I support to call from insert method of CustTable with type post event. It means that once insertion is done to CustTable, system will display recently inserted customer account number. It depends on your business requirement what logic you want to apply here. So here you can develop your required business logic or invoke pre built logic.
9) Go to Tables node in AOT then find out CustTable.
10) Go to insert method of CustTable and right click on it then click on New Event Handler Subscription as shown below.
11) After clicking you will get a new Event handler shown below.
12) Rename the event handler to custCreateInfo and set the property as shown below.
13) Now save your work.
14) Go to Customer form and create a new customer. Here I created a new customer account called “Test-000001”.
15) Once this customer is created system will give your infolog as shown below.
Hope this will help you to understand the event handler in Microsoft Dynamics AX 2012.
No comments:
Post a Comment