Monday, May 23, 2022

update custom fields in BankAccountTrans from LedgerJournalTrans during the posting of journal in D365FO

 update custom fields in BankAccountTrans from LedgerJournalTrans during the posting of the journal in D365FO. Here I am writing the code in the insert method for this I have used a pre-event handler. Check the below code.


class BankAccountTrans_Events
{
    [PreHandlerFor(tableStr(BankAccountTrans), tableMethodStr(BankAccountTrans, insert))]
    public static void BankAccountTrans_Pre_insert(XppPrePostArgs args)
    {
        BankAccountTrans    bankAccountTrans = Args.getThis();
        LedgerJournalTrans  ledgerJournalTrans;

        if (bankAccountTrans.SourceRecId && bankAccountTrans.SourceTableId 
                && bankAccountTrans.SourceTableId == tableNum(LedgerJournalTrans))
        {
            select firstonly1 ledgerJournalTrans
                where ledgerJournalTrans.RecId == bankAccountTrans.SourceRecId;

            bankAccountTrans.NewField1 = ledgerJournalTrans.NewField1;
            bankAccountTrans.NewField2 = ledgerJournalTrans.NewField2;
        }
    }
}


Keep daxing!!


Ref : https://allaboutdynamic.com/2018/06/23/d365-ax7-update-custom-fields-in-bankaccounttrans-from-ledgerjournaltrans/

No comments:

Post a Comment