In Dynamics 365 Finance and Operations, user experience is everything. If a user enters an ItemId, they shouldn't have to manually type the ItemName. We can automate this using the modifiedField override on the table level.
The ModifiedField method is a kernel method that triggers after a field's value has been changed. It's the perfect place to put logic for fetching related data or resetting dependent fields.
The Implementation
On your custom table MNZFRSalesLine, you will override the ModifiedField method. We use a switch statement on the _fieldId parameter to ensure our code only runs when the ItemId is the field being touched.
public void modifiedField(FieldId _fieldId)
{
super(_fieldId);
switch (_fieldId)
{
case fieldNum(MNZFRSalesLine, ItemId):
if (this.ItemId)
{
// Fetch the Item Name using the InventTable find method
// inventTable.itemName() is a common helper method
this.ItemName = InventTable::find(this.ItemId).itemName();
}
break;
}
}
Why do this on the Table instead of the Form?
Reusability: If you add this table to a different form later, the logic stays with the data.
Consistency: Whether the data is changed on a specialized workspace or a simple grid, the behavior remains the same.
Cleanliness: It keeps your Form code-behind light and focused only on UI logic.
Pro Tip: Always call super(_fieldId) at the start to ensure any standard framework logic or event handlers are executed correctly!
