{"id":573,"date":"2019-11-29T16:36:54","date_gmt":"2019-11-29T15:36:54","guid":{"rendered":"http:\/\/daxvisionerp.com\/?p=573"},"modified":"2025-10-27T08:18:50","modified_gmt":"2025-10-27T08:18:50","slug":"chain-of-command-does-not-support-polymorphism","status":"publish","type":"post","link":"https:\/\/daxvisionerp.com\/home\/chain-of-command-does-not-support-polymorphism\/","title":{"rendered":"Chain of Command does not support polymorphism"},"content":{"rendered":"\n<p>In an earlier post, I played around with Chain of Command to explain how it works in general.  <a href=\"http:\/\/daxvisionerp.com\/chain-of-command-coc-example\/\">http:\/\/daxvisionerp.com\/chain-of-command-coc-example\/<\/a> <br>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\u2019s extension method to be called, the parent was called instead. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Explanation through example<\/h2>\n\n\n\n<p>The 2 classes that I augmented are SalesInvoiceJournalPost\nand FormLetterJournalPost. Following is their class hierarchy:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/hierarchy.jpg\" alt=\"\" class=\"wp-image-574\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/1.png\" alt=\"\" class=\"wp-image-581\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/2.png\" alt=\"\" class=\"wp-image-582\"\/><\/figure>\n\n\n\n<p>When I post a sales invoice, another augmentation kicks in:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/postInvoice.jpg\" alt=\"\" class=\"wp-image-575\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/1processJournal.png\" alt=\"\" class=\"wp-image-576\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/1b_processJournalDebugger-1024x57.png\" alt=\"\" class=\"wp-image-577\"\/><\/figure>\n\n\n\n<p>As formletterJournalPostGTE is of type SalesInvoiceJournalPost\nI expect that the method from SalesInvoiceJournalPost_PEP_Extension is called,\nbut this is not the case. The method \u2018formletterJournalPost_PEP_Extension.createInvoiceReporting_PEP(\u2026)\u2019\nis called, but that is the extension of the parent class.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/1c_processJournalDebugger2-1024x84.png\" alt=\"\" class=\"wp-image-578\"\/><\/figure>\n\n\n\n<p>If I validate the type of \u2018formLetterJournalPostGTE\u2019, it is\nSalesInvoiceJournalPost:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/2processJournalFormletter.png\" alt=\"\" class=\"wp-image-579\"\/><\/figure>\n\n\n\n<p>The correct extension method was called.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/daxvisionerp.com\/wp-content\/uploads\/2019\/11\/2processJournalFormletterDebugger-1024x93.png\" alt=\"\" class=\"wp-image-580\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Just be aware that polymorphism is not supported and use the &#8216;as&#8217; keyword as a workaround in the cases when it helps.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/PeterProkopecz\/AX\/tree\/master\/D365FO_ChainOfCommand_Polimorfizm\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/PeterProkopecz\/AX\/tree\/master\/D365FO_ChainOfCommand_Polimorfizm<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"taxonomy-post_tag wp-block-post-terms\"><a href=\"https:\/\/daxvisionerp.com\/home\/tag\/coc\/\" rel=\"tag\">#CoC<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/daxvisionerp.com\/home\/tag\/chain-of-command\/\" rel=\"tag\">Chain of command<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>In an earlier post, I played around with Chain of Command to explain how it works in general. http:\/\/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\u2019s extension method to be called, [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"1080","footnotes":""},"categories":[19,1],"tags":[27,29],"class_list":["post-573","post","type-post","status-publish","format-standard","hentry","category-dynamics-365fo","category-uncategorized","tag-coc","tag-chain-of-command"],"_links":{"self":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":1,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"predecessor-version":[{"id":1394,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/posts\/573\/revisions\/1394"}],"wp:attachment":[{"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daxvisionerp.com\/home\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}