You are on page 1of 12

USING X++ EVENT

HANDLERS LIKE A
PRO
WHAT ARE EVENT
HANDLERS?
Event Handlers sole purpose is to
handle a specific event they were
written to get triggered on.
WHY USE EVENT
HANDLERS?
In Dynamics 365, the
new architecture
does not allow you to
add direct code level
changes.

To cater this we use


Event Handlers.
Can we code now?
WRITE A EVENT
HANDLER IN 3
SIMPLE STEPS
I'm writing a event handler on a form to
disable or enable a control based on user
interaction with a checkbox control.

Checkbox control value Yes - Control


Enabled

Checkbox control value No - Control


Disabled
STEP#1: CREATE A
CLASS
Create a class to write the business logic
inside the event handler.
STEP#2: COPY THE
EVENT HANDLER
For my logic to work, the right choice of
event handler is crucial. Here I'll use the
OnModified event handler of my control to
execute my custom logic. Right click and click
on Copy event handler method & paste in
the class created in step#1.
STEP#3: HANDLING
THE EVENT
The code below enables/disables my control
on the form based on the value of checkbox
control. The code has also been explained in
the comments.
I dont need these. I
could just write a COC
(Chain of command)
HOLD UP!
WHEN TO USE
EVENT HANDLERS?
A method COC is not possible if its private in
nature or Wrappable[false] attribute has been
set. Use of Pre/Post event handlers is possible if
the method has Hookable[true] attribute set.

When you need to implement your business logic


at a specific trigger point such as while records
are being inserted into a table, hence the event
for it OnInserting.
Hi there, I'm Taha

Follow me for more daily posts.

You might also like