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:
![](https://daxvisionerp.com/wp-content/uploads/2019/11/hierarchy.jpg)
![](https://daxvisionerp.com/wp-content/uploads/2019/11/1.png)
![](https://daxvisionerp.com/wp-content/uploads/2019/11/2.png)
When I post a sales invoice, another augmentation kicks in:
![](https://daxvisionerp.com/wp-content/uploads/2019/11/postInvoice.jpg)
![](https://daxvisionerp.com/wp-content/uploads/2019/11/1processJournal.png)
![](https://daxvisionerp.com/wp-content/uploads/2019/11/1b_processJournalDebugger-1024x57.png)
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.
![](https://daxvisionerp.com/wp-content/uploads/2019/11/1c_processJournalDebugger2-1024x84.png)
If I validate the type of ‘formLetterJournalPostGTE’, it is SalesInvoiceJournalPost:
![](https://daxvisionerp.com/wp-content/uploads/2019/11/2processJournalFormletter.png)
The correct extension method was called.
![](https://daxvisionerp.com/wp-content/uploads/2019/11/2processJournalFormletterDebugger-1024x93.png)
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