D365FO – AX – Update Data Entity Target Entity fields with X++
Imagine you want to set the value of a field of the Target Entity of a Data Entity with X ++ code
You have to create an extension class that extends the data Entity, extends the “mapEntityToDataSource” method, and adds your code inside.
[ExtensionOf(tableStr(PurchPurchaseOrderHeaderV2Entity))] //Extends Data Entity
final class Al0PurchPurchaseOrderHeaderV2Entity_Extension
{
public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx) //Extends method
{
switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(PurchPurchaseOrderHeaderV2Entity, PurchTable):
PurchPurchaseOrderHeaderV2Entity purchPurchaseOrderHeaderV2Entity = _entityCtx.getEntityRecord(); //Get Data Entity buffer (Source Entity)
PurchTable purchTable = _dataSourceCtx.getBuffer(); //Get Target Entity buffer
purchTable.MatchingAgreement = PurchAgreementHeader::findAgreementId(purchPurchaseOrderHeaderV2Entity.Al0PurchAgreementRef).RecId; //Set Target entity field
break;
}
next mapEntityToDataSource(_entityCtx, _dataSourceCtx);
}
Comments
Post a Comment