In Dynamics 365 Finance and Operations, the
modifiedField method on tables is crucial for automating data entry. For example, when a user enters an ItemId, we typically want to automatically populate the CustomItemName field.While you could directly override this method on a custom table, what happens when you need to add this logic to a standard table, or when you want to extend existing logic on a custom table like SalesLine? The answer is Chain of Command (CoC).
Using CoC allows us to wrap the standard modifiedField logic, injecting our custom code either before or after the standard execution, all without overlayering or breaking upgrade compatibility.
The CoC Implementation
Here is how you implement CoC on the SalesLine table to populate CustomItemName when ItemId changes. You create a new class that extends the table.
[ExtensionOf(tableStr(SalesLine))]
final class SalesLine_Extension
{
public void modifiedField(FieldId _fieldId)
{
next modifiedField(_fieldId);
switch (_fieldId)
{
case fieldNum(SalesLine, ItemId):
if (this.ItemId)
{
this.CustomItemName = InventTable::find(this.ItemId).itemName();
}
break;
}
}
}
Key CoC Best Practices Shown Here:
next modifiedField(_fieldId);: This is mandatory. It ensures that any standard code or other extensions in the chain still run. I’ve placed it at the beginning so our custom assignment (this.CustomItemName= ...) happens after any standard logic.Table Context: Inside the CoC method, you have direct access to the table buffer using
this.Extensions: This code doesn't touch the original
SalesLinetable object, making it cleanly separated and easy to manage during updates.
Using Chain of Command ensures your custom logic is modular, upgrade-safe, and plays nicely with other extensions in the system.
