Today I am writing continuing the article which I have posted last time, on the very hot topic which is “Events in microsoft dynamics NAV”. If you have not followed the first part you can read it here.
This article show a complete demonstration about how to play with the events in Microsoft Dynamics NAV.
Suppose our business scenario is whenever a Customer is created in Dynamics NAV we should add it in our custom table as well. We will perform this activity by creating our custom codeunit say 50005 and then defining a method (event) say CreateCustomerInMyCustomerTableOnAfterModifyEvent in this codeunit. This new event will be the subscriber of the event OnAfterModifyEvent in Customer Table 18.
- Create a MyCustomer Table.
- Create a codeunit say “Create My Customer”.
- Create a function in this code unit a name it CreateCustomerInMyCustomerTableOnAfterModifyEvent
- Go to the function properties and set the properties as:
- Event: Subscriber
- EventPublisherObject: Table Customer
- EventFunction: OnAfterModifyEvent
- Close the property window and save the codeunit.
- Now go to the Locals of your function CreateCustomerInMyCustomerTableOnAfterModifyEvent and define a variable of type record to insert new item in MyCustomer Table.
- Now write the code in your function. MyCustomer.INIT;
MyCustomer.”No.” := Rec.”No.”;
MyCustomer.”Customer Name” := Rec.Name;
MyCustomer.”Customer Email” := Rec.”E-Mail”;
IF NOT MyCustomer.INSERT THEN
- Compile and save the codeunit.
- Now go to the Windows Client and create a new customer. You will see that customer record is in your custom table too.
Congratulations! You have created your first event based application in Dynamics NAV. If you like my post, don’t forget to share it. 🙂
To Download the Demo Files: Click Here