Tuesday, September 23, 2025

Automating Consolidate Account Updates for New Voucher Transactions in D365 Finance and Operations

 Ensure the Consolidate Account field is automatically updated for all new voucher transactions based on the Consolidate MainAccount setup, to maintain consistency in financial consolidation and reporting.

[ExtensionOf(classStr(LedgerVoucherTransObject))]

internal final class LedgerVoucherTransObject_Extension

{

    public void initFromLedgerPostingTransaction(

        LedgerPostingTransactionTmp _ledgerPostingTransaction,

        LedgerPostingTransactionProjectTmp _projectPostingTransaction)

    {

        next initFromLedgerPostingTransaction(_ledgerPostingTransaction, _projectPostingTransaction);


        MainAccountConsolidateAccount   consolidationAccount;

        LedgerParameters                ledgerParameters = ledgerParameters::find();


        RecId mainAccount = MainAccount::findByLedgerDimension(generalJournalAccountEntry.ledgerDimension).RecId;


        select firstonly consolidationAccount

            where consolidationAccount.MainAccount == mainAccount

                && consolidationAccount.ConsolidateAccountGroup == ledgerParameters.ConsolidateAccountGroup;


        generalJournalAccountEntry.ConsolidateAccountName   = consolidationAccount.Name;

        generalJournalAccountEntry.ConsolidationMainAccount = consolidationAccount.ConsolidationMainAccount;

    }

}

=============================================

[ExtensionOf(classStr(LedgerVoucherTransObject))]

internal final class LedgerVoucherTransObject_Extension

{

    public void initFromLedgerPostingTransaction(

        LedgerPostingTransactionTmp _ledgerPostingTransaction,

        LedgerPostingTransactionProjectTmp _projectPostingTransaction)

    {

        next initFromLedgerPostingTransaction(_ledgerPostingTransaction, _projectPostingTransaction);


        MainAccountConsolidateAccount consolidationAccount;

        LedgerParameters              ledgerParameters = ledgerParameters::find();


        RecId mainAccount = MainAccount::findByLedgerDimension(generalJournalAccountEntry.ledgerDimension).RecId;


        select firstonly consolidationAccount

            where consolidationAccount.MainAccount == mainAccount

                && consolidationAccount.ConsolidateAccountGroup == ledgerParameters.ConsolidateAccountGroup;


        generalJournalAccountEntry.ConsolidateAccountName   = consolidationAccount.Name;

        generalJournalAccountEntry.ConsolidationMainAccount = consolidationAccount.ConsolidationMainAccount;

    }

}

No comments:

Post a Comment

Automating Consolidate Account Updates for New Voucher Transactions in D365 Finance and Operations

  Ensure the  Consolidate Account  field is automatically updated for all new voucher transactions based on the  Consolidate MainAccount set...