Microsoft Solutions Partner · Business Applications · Data & AI · Digital & App Innovation

X++ Development

Chain of Command in D365 F&O: Extending Without Overlayering

In Dynamics 365 Finance & Operations, you can’t modify Microsoft’s source code directly. Instead, you extend it. The most powerful tool for this is Chain of Command (CoC), which lets you wrap standard methods with your own logic.

What Chain of Command looks like

[ExtensionOf(classStr(SalesFormLetter))]
final class SalesFormLetter_EDG_Extension
{
    public void run()
    {
        // Logic before the standard method
        this.edgValidateCustomRules();

        next run();   // Call the standard (and other extensions')

        // Logic after the standard method
        this.edgNotifyWarehouse();
    }
}

Key points:

  • The class is decorated with ExtensionOf and must be final.
  • The class name must end in _Extension. Add a prefix (like EDG) to avoid name clashes.
  • Calling next is mandatory (with the exception of methods marked [Replaceable]).
  • You can access protected and public members of the extended class.

What you can extend

CoC works on classes, tables, forms, form data sources, form data fields and form controls. For example, to add validation to a table’s validateWrite:

[ExtensionOf(tableStr(CustTable))]
final class CustTable_EDG_Extension
{
    public boolean validateWrite()
    {
        boolean ret = next validateWrite();

        if (ret && !this.CustGroup)
        {
            ret = checkFailed("Customer group is required.");
        }
        return ret;
    }
}

Best practices

  1. Keep wrappers thin. Put business logic in your own classes and call them from the wrapper. It’s easier to test and reuse.
  2. Prefix everything. New methods, fields and classes should use your model prefix.
  3. Don’t assume ordering. Multiple extensions may wrap the same method, and their execution order isn’t guaranteed.
  4. Prefer CoC over pre/post event handlers for new code. It’s more readable and gives access to protected members.
  5. Request extensibility from Microsoft when a method you need is private or not wrappable.

Why it matters for your business

Extension-based development is what makes D365 customizations upgrade-safe. When Microsoft ships a service update, your code keeps working because it doesn’t touch theirs. That is a big reason the total cost of ownership of D365 is lower than overlayered AX.

Need experienced X++ developers? See our Dynamics 365 F&O development services.

Talk to a Dynamics 365 consultant

Book a free 30-minute consultation. We'll review your goals and outline a practical plan, with no obligation.

Start the conversation