Using the new Chain of Command feature in X++
Recently a new feature for X++ developers was announced by Michael Fruergaard Pontoppidan (MFP) called Chain of Command. I knew I would want to try it out as soon as I had some time and it is pretty slick. This post will show it in action with a simple example in Microsoft Dynamics 365 Enterprise edition (AX7).
My example is nothing flashy. It shows how to raise an Infolog message when a sales line is added to a sales order and the customer does not have a credit rating. Since I know that when you add a sales line, the SalesLineType class is called and the insert method is used. My plan was to create an extension for the SalesLineType class and put custom code in the insert method. Here is the code for the new extension class:
final class SalesLineType_Extension
public void insert(boolean dropInvent, boolean findMarkup, Common childBuffer, boolean _skipCreditLimitCheck)
//get customer for evalation of credit rating
custTable = CustTable::find(salesLine.CustAccount);
info("Customer on sales line has no credit rating!");
// must call next when using Chain of Command pattern
next insert(dropInvent, findMarkup, childBuffer, _skipCreditLimitCheck);
Note the usage of the ExtensionOf attribute and the requirement to use the next keyword. The compiler told me to mark the class final so I did that also. Since the insert method in the SalesLineType class is public, I also had to use public in the extension class.
For reference, here is my project which is based on a new package in Visual Studio:
Here is the Infolog when saving a new sales line:
One issue I ran into was around debugging with Visual Studio. The symbols would not load for my breakpoints. To resolve this, I marked the below setting in the Visual Studio debugging options. In addition to this one, there is also a similar setting in the Dynamics 365 node.
Chain of Command was released with Platform Update 9. You can find more information in this “What’s New or Changed in Dynamics 365 for Finance and Operations” article.