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
ExtensionOfand must befinal. - The class name must end in
_Extension. Add a prefix (likeEDG) to avoid name clashes. - Calling
nextis 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
- Keep wrappers thin. Put business logic in your own classes and call them from the wrapper. It’s easier to test and reuse.
- Prefix everything. New methods, fields and classes should use your model prefix.
- Don’t assume ordering. Multiple extensions may wrap the same method, and their execution order isn’t guaranteed.
- Prefer CoC over pre/post event handlers for new code. It’s more readable and gives access to protected members.
- 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.