Chain of Command in D365 F&O — The Right Way to Extend Standard Code**
Before Chain of Command (CoC) arrived with platform update 8, extending Microsoft's standard X++ code meant either overlayering (editing Microsoft's own objects directly — a maintenance nightmare) or relying on limited event handlers that couldn't wrap logic around a method. CoC solved this cleanly.
What CoC actually does
CoC lets you create an extension class that "wraps" around an existing class or table method. Inside your extension method, you call next(), which hands control back to the base method (or the next extension in the chain, if multiple exist). This means you can run code before, after, or even around the original logic — and you can inspect or modify the return value.
[ExtensionOf(classStr(SalesLine))]
final class SalesLine_Extension
{
public void validateWrite()
{
next validateWrite(); // calls base logic
if (this.SalesQty <= 0)
{
throw error("Quantity must be greater than zero.");
}
}
}
Why next() matters
next() isn't just a formality — it's how Microsoft guarantees multiple ISVs and customizations can extend the same method without stepping on each other. Each extension in the chain calls next(), which passes control down the line until it hits the base implementation. Skip calling next(), and you break the base logic (and potentially every other extension layered on top of it).
Key rules to remember
- CoC classes must be declared
final. - You can extend classes, tables, forms (data sources, form control methods), and even static/class declaration methods (with some version-specific caveats).
- You cannot change method signatures — the extension must match exactly.
- CoC does not replace event handlers entirely; each has its place (see the next topic).
When to use CoC vs. overlayering
Never overlayer in current cloud-hosted D365 F&O — it's not even architecturally possible outside on-prem PU builds. CoC (along with event handlers) is the standard, supported extension model. Reach for CoC when you need to modify behavior around an existing method — especially when you need to alter parameters, cancel execution, or manipulate the return value.

Top comments (0)