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 “mapEntityToDataSource” method and add 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);
    }

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...