Hi,All this is the part II of Eventing framework.part1 is here
Automatic events are the events that occur on when something happen(not usual) like phone ringing,sms e.t.c.There are of two types
- Pre Event handler: This is called before the execution of method (in a table or a class).
- Post Event handler:This is called after the execution of method(in a table or a class)
Note:These event handler can be defined against a method in a class or a table.
Here is the example:
I have create a class ‘AsimPrePostHandlerClass’
And written Pre/Post Event handler here.
In Pre Event Handler,I am just intializing customerTable buffer with the sender object which is actually a table buffer,then checking if the custAccount value is ‘4010’then the error should be prompted on inserting.
In the Post Event above, I am just prompting the notification that Account selected has been successfully added.
Also i have create a table conting two fields and created a validateWrite method
Now subscribe Pre/Post Event handler with the method(see below)
Now associating Pre/Post Event handler to the Pre/Post methods that i have written before in the class
Finally i have created a simpleListDetails form via table the i have create before
Now lets try a record (let say Cust Account = 4000)
See above the Post Event Handler called.Also pre event handler was also called but my check is for CustAccount = 4000 that why it didn’t show any message
Now lets try to enter Customer Account = 4010)
See the Pre Event Handler is called again but now its showing the a message as well(thats was my check) and then post event handler is also called
Also note above that since the pre event handler is called but still value can be saved , which should be not. SO the idea is if we want to cancel all the handlers like
if pre event is failed then method and Post should not be called then we need to throw an exception which apparently aborted all execution.But first let see the sequence of calling.In the validate write method i have added an info
Now lets try so enter a record Customer Account = 4000
See so first Pre event called then method ‘validateWrite’ called and finally Post even called
Now if we want to abort things the we need to throw an exception like
Now i am throwing an exception here in pre event handler.now let c whats happen.Let try to enter a record Customer Account = 4000
See now the all the executions have been aborted and also it stopping me to enter a record in it as well
Hope this blog may clear Pre and Post Event handler concepts.