Search This Blog

Thursday 21 February 2013

Eventing Framework In Microsoft Dynamics AX 2012 Part 2

Now In this Post I will guide you how to create Events.

We have basically already discuss that what events are.Now In Microsoft Dynamics AX two terminologies are used these are.

1.Pre Events.

2.Post Events.

Pre Events are those that called before the method and post events are those that are called after the method.

Now I will show you the Scenario I can we use Pre and Post Events.

Below are the some steps for creating and using the events.

Step 1:

First we will create the simple table with two fields i.e  as you can see this in the image below.

 Step 2:

Now we will create the SimpleListDetail Form

As you already know how to create a form.

Now after creating the SimpleListDetailsForm drag the table that we have created earlier on the datasource node of that SimpleListDetailForm.and from datasource drag the fields to the details header and grid node of the design node.

As you can see in the image below.


























Run that form it should be exactly like below form.














Step 3:

Now will create a method on the table i,e assignned to to this form.The is validatewrite method and before and after that method we will create events.What I am trying to say is one event will fire before the execution of that method and one event will fire after the execution of that methods.

First we will create the method as you can see in the image  below

























Step 4:

After Creating the method we will assign pre and post events to it.

Just right click the method and than select the new event handler subcription.

As you can see in the below image.

























Now when you create the new event handler just go into the properties of the that eventhandler and than set the properties to the " Called When" =  Pre and than "Class name" = name of the class and "method" = name of the method that will be called before the execution of that method.

As you can see in the image below.
















Now inside the zahidpre method I am just showing the message inside the info box that the pre method is called.

Now its quit easy to create this event handler method i.e zahidpre.

Just right click the class and than select new->pre-post-eventhandler.

As you can see in the image below.




















An Event Handler will be created as you can see in the image below.











Now repeat the step 4 for the Post Event Handler.Only one thing you should do is when creating the Eventhandler on table just set its property "called when" = Post.

As you can see in the image below.












Now I will show you the demo that how pre and post event handlers are run when we run the form.

As you already know that inside the pre event handler I am showing the info message that "Pre is called" and same thing for the post event handler that I am showing that the "Post is called" and inside the validate write method I am showing that the "This called form the validate write method".

Now I will run the form and than insert the record and during the insertion of the record first pre event  will be call and than the validate method will be call and than the post event will be called.

 As you can see in the above form that I have inserted the record  and when I click the new button or close the form the data that I have write will going to insert into the record and that pre event will call and than the validate write method will call and than post event will call.

As you can see the messages of the info box inside the below image.



 
















Now This was all related to the Event Framework part.

I hope you like that post.If you guys have any issues than feel free to comment or contact me :) :)

If you want to go to eventing framework part 1 post than click on the link below.

Eventing Framework Part 1

Thanks

Muhammad Zahid.

No comments:

Post a Comment