Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

How to get Closing balance for offsetaccount in general journal

Posted on by
this my Hello dev,

I'm working on a business requirement, in general journals whenever general journal is posted I need to bring the closing balance of particular main account, that closing balance should come from the Trial Balance, I'm not able to figure it out! can somebody please suggest me how to bring the closing balance


Thanks in advance,


This is my code
 
[ExtensionOf(classStr(LedgerJournalPost))]
final class ADCG_LedgerJournalPost_Class_Extension
{
    public static void post(
        Common  _record,
        TableId _tableId,
        NoYes _transferErrors,
        boolean _splitLargeJournal,
        boolean _suppressClientMessages,
        str _callingFormName,
        LedgerJournalEngine _ledgerJournalEngine,
        boolean _skipIL_RU,
        LedgerJournalCheckPostResults _results_R,
        boolean _progressBarHide)
    {
        next post(_record,_tableId,_transferErrors,true,false,'',null,false,null,false);
      
        LedgerJournalPost::getClosingBalanceForMainAccount();
    }
    static void getClosingBalanceForMainAccount()
    {
        LedgerJournalTable ledgerJournalTable;
        LedgerJournalTrans ledgerJournalTrans;
        LedgerTrialBalanceTmp trialBalanceTmp;
        LedgerTrialBalanceDP trialBalanceDP = new LedgerTrialBalanceDP();
        List selected = new List(Types::Enum);
        MainAccount mainAccount;
        MainAccount mainAccountOffset;
        // Specify the date range for the trial balance
        date fromDate = mkDate(1, 1, 2024); // Start date (adjust as needed)
        date toDate = mkDate(31, 12, 2024); // End date (adjust as needed)
        // Get the main account and offset account
        mainAccount = MainAccount::findByLedgerDimension(ledgerJournalTrans.LedgerDimension);
        mainAccountOffset = MainAccount::findByLedgerDimension(ledgerJournalTrans.OffsetLedgerDimension);
        // Calculate balances for the main account
        LedgerTrialBalanceTmp::calculateBalances(
            trialBalanceTmp,
            mainAccount.MainAccountId, // Use the current main account number
        fromDate,
            toDate,
            false, // Opening balances
        false, // Closing balances
        false, // Include transactions
        selected,
            true, // Include financial dimensions
        true, // Include balances
        Ledger::current()
        );
        // Retrieve the calculated balance
        trialBalanceTmp = trialBalanceDP.getLedgerTrialBalanceTmp();
        if (trialBalanceTmp)
        {
            AmountCur closingBalance = trialBalanceTmp.EndingBalance;
            if (mainAccountOffset && closingBalance < mainAccountOffset.ADCG_CreditLimitReal)
            {
                // Display a warning message
                info(strFmt("Warning: The ending balance for %1 exceeds the credit limit. Balance: %2",
                        DimensionAttributeValueCombination::find(trialBalanceTmp.LedgerDimension).DisplayValue,
                        closingBalance));
            }
        }
    }

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,983 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans