Updating Field Values During Data Entity Import in Dynamics 365 Finance & Operations
In Dynamics 365 Finance & Operations (D365FO), there are scenarios where data needs to be
enriched or recalculated during data import. This can be achieved by overriding the
mapEntityToDataSource() method in the Data Entity.
This blog explains a real-world example where the Vendor Name is populated automatically while importing vendor invoice data through a data entity.
Business Requirement
- Vendor invoice data is received from an external system
- Only the Vendor Tax ID is provided in the import file
- Vendor Name should be derived automatically during the import
Technical Approach
We override the mapEntityToDataSource() method and update the target datasource buffer
before the record is written to the database.
mapEntityToDataSource method is executed during import and is
ideal for deriving or modifying values dynamically.
X++ Code Implementation
public void mapEntityToDataSource(
DataEntityRuntimeContext _entityCtx,
DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
super(_entityCtx, _dataSourceCtx);
if (_dataSourceCtx.name() ==
dataEntityDataSourceStr(TESTEdicomIncomingDocument, TESTVendInvoiceProcess))
{
TESTVendInvoiceProcess TESTVendInvoiceProcess = _dataSourceCtx.getBuffer();
LTMVendTable ltmVendTable;
VendTable vendTable;
DirPartyTable dirParty;
select firstOnly ltmVendTable
where ltmVendTable.CountryDocNum == this.TaxId
join firstOnly vendTable
where vendTable.AccountNum == ltmVendTable.AccountNum;
select firstOnly dirParty
where dirParty.RecId == vendTable.Party;
TESTVendInvoiceProcess.VendorName = dirParty.Name;
}
}
When to Use mapEntityToDataSource()
- Derive values during import
- Apply default values
- Validate or adjust incoming data
- Populate fields not provided by the source system
Conclusion
The mapEntityToDataSource() method is a powerful extension point in D365FO data entities.
Using it correctly helps ensure clean, consistent, and business-ready data during imports.
This pattern is especially useful in integration scenarios where source systems provide minimal data and enrichment is required on the D365FO side.

Like
Report
*This post is locked for comments