Hi,
I am working on D365 FO. I am bit confusing on Extensions and Event handlers.
When we can go for Extensions and When we can go for Event handlers..? and what is the difference between these two.
--
Regards
ARK
Hi Toayyappa,
In addition, one thing is that you need to be aware that using event handlers in extension classes can bother you.You can read this blog:
[View:https://daxmusings.codecrib.com/2018/06/accidental-code-extensions.html:750:50]
Extension is a much broader concept. You can use extensions to enhance tables, forms, queries, classes and so on.
In classes, you can use class augmentation / Chain of Command to create an enhanced version of the base class. The syntax for this is to use "extensionOf" attribute in the class. Using class augmentation / Chain of Command is much more powerful than event handlers, since you have access to all public and protected members of the class. Also with CoC you can add your code to run in the same transaction scope than the method that you hook into.
Event handlers can only be used on public methods, or with predefined events. You can't run event handler in the same transaction scope than the original method.
In general you should use Chain of Command when possible. Sometimes it's not possible and you need to use event handlers. In most scenarios both are possible, but CoC is easier to read and more powerful so why not use it.
Here's MS documentation about CoC: docs.microsoft.com/.../method-wrapping-coc
There are many discussions about this topic, which you can find by searching the web for "dynamics 365 operations chain of command event handler", here are some:
community.dynamics.com/.../difference-between-coc-and-event-handler-in-d365
community.dynamics.com/.../can-i-use-event-handlers-pre-or-post-instead-of-coc
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Sohaib Cheema 789 User Group Leader
André Arnaud de Cal... 607 Super User 2025 Season 2
Martin Dráb 497 Most Valuable Professional