Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Can i use Event handle...
Finance forum

Can i use Event handlers (Pre OR Post ) instead of CoC ?

(0) ShareShare
ReportReport
Posted on by 4

Hi All,

Can you please let me know the CoC is behave like Event handlers (Pre OR Post ) ? Means can i use Event handlers (Pre OR Post ) instead of CoC ?

Please give me more shed on this.

Thanks!

  • Verified answer
    Jie G Profile Picture
    on at
    RE: Can i use Event handlers (Pre OR Post ) instead of CoC ?

    Hi @rp@n,

    Here is a blog with code samples for you to understand community.dynamics.com/.../ax7-d365-chain-of-command-with-example . You can write your code and test it.

    You can add some pre and post event handlers and call them together with chain of command methods to test how they relate to each other.

    Then you can see the pre and post event handlers run after and before the chain of command calls. So chain of command wraps the base method, and its pre and post event handlers all together. Just as chain of command, the event handler methods are also called in a random order.

  • Verified answer
    Joris dG Profile Picture
    17,775 on at
    RE: Can i use Event handlers (Pre OR Post ) instead of CoC ?

    If you read the official documentation you'll notice the handlers are not talked about much, instead chain of command is the preferred way. It has more features and is easier to read. You don't need a pre and a post handler but can do one method and just call next, and do logic before and after. You also have the benefit of being inside a class instance so you can add member variables, call protected methods, etc.

    docs.microsoft.com/.../extensibility-home-page

    I think I have mentioned this in other posts from you - you have valid questions but seem to be missing basic knowledge. I'm still encouraging you to seek out training somewhere since you will greatly benefit from someone just going through these basics with you, as opposed to you having to come here and ask basic questions and waiting for replies.

  • Verified answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Can i use Event handlers (Pre OR Post ) instead of CoC ?

    As usual, you can find answer to many "can I?" questions by simply trying it. As already pointed out by others, yes you can use event handlers instead of CoC. But usually it doesn't make sense to use event handlers in scenarios where CoC is possible.

  • Verified answer
    Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: Can i use Event handlers (Pre OR Post ) instead of CoC ?

    Yes, you can, the question is why you would ever do it. CoC was developed to overcome many limitations of these handlers and I'm not aware of any good reason for using the legacy approach. Simply don't do it despite the fact that you can.

  • Sohaib Cheema Profile Picture
    46,614 User Group Leader on at
    RE: Can i use Event handlers (Pre OR Post ) instead of CoC ?

    It depends.

    e.g. if you want to make use of local variables Event Handlers can be less handy as compared to 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.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans