Chain of Command extension model in F&O
How Chain of Command lets X++ developers extend F&O standard logic safely — wrap methods, call next, and the upgrade-safe pattern.
In the modern Dynamics 365 Finance and Supply Chain platform, customisation happens through extensions — separate models that augment Microsoft's standard code without modifying it directly. Chain of Command (CoC) is the X++ language pattern that makes this work safely: an extension method wraps a standard method, runs its own logic, and calls next to continue the standard execution. The result is upgrade-safe customisation that survives platform updates.
The pre-extension world. In Dynamics AX (the predecessor to F&O), customisation typically meant editing Microsoft's code directly — adding lines to salesTable.insert() or purchTable.update(). This made upgrades painful: every customisation had to be re-merged with the new platform version, and the more customisations, the worse the upgrade.
The extension model. Modern F&O forbids direct modification of Microsoft objects. Instead, developers write extension models that add or modify behaviour through:
- Class extensions — add methods or fields to standard classes.
- Table extensions — add fields, methods, indices, relations.
- Form extensions — add fields, controls, datasources.
- Chain of Command — wrap standard methods to inject custom logic.
Chain of Command — the mechanics. A CoC method in an extension class:
[ExtensionOf(classStr(SalesTableForm))]
final class SalesTableForm_Extension
{
public void init()
{
// Custom code before standard method
info("About to init");
next init(); // Call the standard method
// Custom code after standard method
info("Finished init");
}
}
The [ExtensionOf] attribute tells the compiler the class wraps SalesTableForm. The method name matches a standard method; next init() calls the next implementation in the chain — eventually reaching Microsoft's standard. The extension method can do work before, after, or instead of (by omitting next).
The chain. Multiple extensions can wrap the same method. They form a chain:
- Microsoft's standard at the base.
- Extension A wraps it.
- Extension B wraps Extension A.
- The user-facing call goes through B → A → standard.
Each extension's next calls the next layer down. The order is determined by the model installation order; deterministic but customers don't typically design for specific chain orders.
What can be wrapped.
- Public and protected methods of standard classes, forms, and tables.
- Static methods — also wrappable.
newanddisposemethods — for lifecycle injection.- Form-level methods — for UI behaviour modification.
Private methods cannot be wrapped — they're encapsulated implementation details.
Common CoC patterns.
- Pre-validation — wrap
validateWrite()to add custom validation rules. Callnextonly if custom rules pass. - Post-creation hooks — wrap
insert()to do follow-on actions (notifications, integration triggers) after successful insert. - Behavioural override — wrap
update()to suppress or modify standard behaviour under specific conditions, then conditionally callnext. - Audit logging — wrap any modify method to log changes to a custom audit table.
- Integration triggers — wrap post-completion methods to trigger external integrations.
CoC vs event handlers. F&O supports two related patterns:
- Chain of Command — wraps methods; can modify the call chain before, after, or instead of.
- Event handlers — subscribe to predefined events; can't suppress or modify the call chain, only observe.
CoC is more powerful (can intercept and modify); event handlers are more isolated (purely observational). Choose based on whether you need to alter behaviour or just react to it.
Performance and overhead. Each CoC layer adds a small overhead — method-call indirection through the chain. For high-frequency methods (called millions of times), CoC overhead can add up. Profile if a heavily-wrapped method becomes a bottleneck.
Upgrade safety. This is the whole point. When Microsoft releases a new platform version:
- Standard code changes — CoC wraps it as before; chain continues to work unless Microsoft removed or renamed the wrapped method.
- New behaviour — CoC extensions still apply; the new behaviour layers in alongside.
- Breaking changes — Microsoft documents deprecated methods; CoC code referencing them needs update.
For the most part, CoC code survives platform updates without modification — the dramatic improvement over the AX-era customisation model.
Common pitfalls.
- Forgetting
next— the extension intercepts and never calls Microsoft's code. Side effects may surprise. - Calling
nextin wrong position — putting custom logic afternextwhen it should be before, or vice versa. - Order-dependent chains — when multiple extensions wrap the same method, behaviour can depend on installation order. Avoid.
- Long-running CoC — heavy work inside a wrap can slow the standard operation.
Operational reality. CoC is the foundation of modern F&O customisation. Developers fluent in it produce maintainable, upgrade-safe extensions; those who try to revert to direct modification cannot in the SaaS model. The discipline pays back across years of platform updates.
Related guides
- Custom services and OData endpoints in F&OHow to expose Dynamics 365 Finance / SCM functionality to external systems — custom services in X++, OData endpoints from data entities, authentication and limits.
- Form extensions in Dynamics 365 Finance and OperationsHow to extend forms in F&O — extending standard forms, adding controls and groups, handling events, and avoiding common form-extension pitfalls.
- X++ — the language behind Dynamics 365 Finance and OperationsWhat X++ is, where it came from, and how it's used in F&O — language features, the application object tree, and the modern developer workflow with Visual Studio.
- Machine learning forecasting in Dynamics 365 Supply ChainHow the demand forecasting service in D365 SCM uses Azure ML — historical demand, parameter tuning, and the operational realities of accepting or overriding ML forecasts.
- The Dynamics 365 Finance and SCM security modelHow role-based security works in Dynamics 365 Finance and SCM — duties, privileges, roles, segregation of duties, and extensible data security.