Using the new Chain of Command feature in X++

By Chris Roehrich | September 28, 2017

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).

Syntax Requirements

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:

[ExtensionOf(classStr(SalesLineType))]
final class SalesLineType_Extension
{
    public void insert(boolean dropInvent, boolean findMarkup, Common childBuffer, boolean _skipCreditLimitCheck)
    {
        CustTable   custTable;        
        
        //get customer for evalation of credit rating
        custTable = CustTable::find(salesLine.CustAccount);

        if(!custTable.CreditRating)
        {
            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:

Project in visual studio

Here is the Infolog when saving a new sales line:

Infolog of a new sales line

Debugging Tip

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.

Debugging in visual studio

Chris Roehrich
Our Verified Expert
Chris Roehrich

Chris Roehrich brings more than 20 years of engineering and support experience with Microsoft technologies, specializing in Dynamics GP and Dynamics AX / Dynamics 365 Finance and Supply Chain. His background includes deep work in developer support—focusing on SQL performance, system migrations, and integration tooling—and advanced troubleshooting across CRM connectors, AIF services, and SRS report customizations.
Recent projects include resolving AX code-level issues, optimizing version control workflows, and advising on debugging strategies for X++ and C# environments. With a sharp technical eye and a commitment to stability, Chris supports complex systems with clarity and care.

Read More from Chris Roehrich

Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!