web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Questions about Deciding between data-events or Chain of Command

(0) ShareShare
ReportReport
Posted on by 332

Hello..

The next part from a book , can anyone explain the yellow part 

When writing data-event handlers, we must also take into account Chain of Command
extensions. The Using Chain of Command to initialize data recipe shows an alternative to using
data-events.


In this specific case, I would opt for Chain of Command, and the decision is based on many
factors, including the following:


       1- Looking up data in order tables, where there is an InitFrom method for that
           table that can be used instead.
        2- Is the data likely to be inserted using a set-based operation with triggers
            disabled, such as insert_recordset? These are common in journal and
            transaction tables, and when data is inserted or updated through a data entity.


Data-events are ideal on main and worksheet tables, but care should be taken when using
this on journal or transaction tables. Code-based delegates should be safe, as are the
public methods that are designed to initialize data. Although we have discussed test
projects, writing tests for this purpose can seem pointless. However, it is a common source
for regression as Microsoft can change the way data is written to improve performance.

Pre- and post-event Handlers


Pre-and post event handlers are the last resort when we need to hook into standard code.
They are very prone to breaking changes, and can often compile and then fail at runtime.
They are mentioned here for completeness.
The only time you should encounter pre-post handlers is in code upgraded from AX 2012.
In these cases, we should change the code so that it either handles a delegate or uses a
Chain of Command.

Thanks experts.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,109 Super User 2025 Season 2 on at

    Hi Ahmed,

    I'm missing the full context of this paragraph. Can you ask a specific question? Otherwise, probably, you can ask the author what he was trying to write down. Or do you want to know when to use CoC or when to use delegates?

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

    Yes i just want to know is right to use the data event with main and worksheet tables ?

    Is Insert_recordSet disabled with data event handler or with COC ?

    is there general reason makes Pre-and post event handlers  fails in run time even it build successful ?

  • Suggested answer
    Rahul Mohta Profile Picture
    21,032 on at

    try and avoid pre/post event handlers

    could use framework events instead and where possible use CoC as execution is guaranteed and could also control the sequence by smartly using it

    Events in general are broadcast and using them would not guarantee execution sequence hence troubleshooting would be tough

    hope it helps

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

    what do you mean by  execution sequence ?

    Thank you

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

    Thanks for all experts .

    my questions are ?

    is there any problem when using insert_recordset with events or OCC ?

    why pre/post event handlers not guarantee execution sequence ?

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    If you have overwrited method, event handler or CoC with the insert/update/delete method/event then set based operations will fall back to row by row execution. But of course your set based code will work, it's just not executed as set based.

    About the execution sequence, that's just how it works. Different systems can have different extensions and they should not be designed to be dependent of each other, or their execution sequence.

  • Verified answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at

    Customer account statement report (CustAccountStatementExtDP) class has used insert_recordset and I did not have any issues in extending this class using CoC. You just need to find out the correct implementation way to achieve it and not necessirily you have to use insert_recordset in the extended class.

    I went through this post way before and found it good read so have a read through to understand even handler execution sequence too devblog.sertanyaman.com/.../

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

    Thanks all

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans