In an earlier post, I played around with Chain of Command to explain how it works in general. https://daxvisionerp.com/chain-of-command-coc-example/
This post will be more advanced. Chain of command does not support polymorphism. I have augmented 2 classes that are already in Parent-child relation and when I expected the child class’s extension method to be called, the parent was called instead.
Explanation through example
The 2 classes that I augmented are SalesInvoiceJournalPost and FormLetterJournalPost. Following is their class hierarchy:
When I post a sales invoice, another augmentation kicks in:
As formletterJournalPostGTE is of type SalesInvoiceJournalPost I expect that the method from SalesInvoiceJournalPost_PEP_Extension is called, but this is not the case. The method ‘formletterJournalPost_PEP_Extension.createInvoiceReporting_PEP(…)’ is called, but that is the extension of the parent class.
If I validate the type of ‘formLetterJournalPostGTE’, it is SalesInvoiceJournalPost:
The correct extension method was called.
Conclusion
Just be aware that polymorphism is not supported and use the ‘as’ keyword as a workaround in the cases when it helps.
https://github.com/PeterProkopecz/AX/tree/master/D365FO_ChainOfCommand_Polimorfizm