web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Pulling Data from Trial Balance Feature in D365 Finance and Operations to Custom Table

(1) ShareShare
ReportReport
Posted on by 90

Hello everyone,

I’m working on an integration project in D365 FO where I need to pull and store trial balance data from the standard Trial Balance feature located under General Ledger > Inquiries and Reports. I want to extract this data into a custom table (NPLLedgerTrialBalance) so I can send it through Data Entity. I am using the LedgerTrialBalanceDP class along with a contract (LedgerTrialBalanceContract) to filter data by fiscal period and fiscal year. Additionally, I am pulling DisplayMainAccountCategory from a parameter field in D365.

Below is a shortened version of my code

 

public void trialBalance(FiscalCalendarPeriod calendarPeriod)
{
    NPLLedgerTrialBalance _TrialBalance = null;
    LedgerTrialBalanceTmp _ledgerTrialBalanceTmp = null;
    TransDate iniDate = calendarPeriod.StartDate;
    TransDate endDate = calendarPeriod.EndDate;
    List postingLayers;

    // Update dimension focus balance
    DimensionFocusUpdateBalance::updateBalance(DimensionHierarchy::findByTypeAndName(DimensionHierarchyType::Focus, "MA + Brand + Location + Dept"));

    // Posting layers
    postingLayers = new List(Types::Enum);
    postingLayers.addEnd(CurrentOperationsTax::Current);

    // Contract setup
    LedgerTrialBalanceContract trialBalanceContract = new LedgerTrialBalanceContract();
    trialBalanceContract.parmFromDate(iniDate);
    trialBalanceContract.parmToDate(endDate);
    trialBalanceContract.parmIncludeOpening(true);
    trialBalanceContract.parmIncludeClosingAdjustments(true);
    trialBalanceContract.parmIncludeClosingTransactions(true);
    trialBalanceContract.parmPostingLayers(postingLayers);
    trialBalanceContract.parmPrimaryDimensionFocus(LedgerParameters::find().NPLDimensionSetName);
    trialBalanceContract.parmDisplayMainAccountCategory(true);

    // Process data
    LedgerTrialBalanceDP trialBalanceDP = new LedgerTrialBalanceDP();
    trialBalanceDP.parmDataContract(trialBalanceContract);
    trialBalanceDP.processReport();

    // Iterate over LedgerTrialBalanceTmp and insert into NPLLedgerTrialBalance
    _ledgerTrialBalanceTmp = trialBalanceDP.getLedgerTrialBalanceTmp();

    while select _ledgerTrialBalanceTmp
    {
        _TrialBalance.clear();
        _TrialBalance.AmountCredit = _ledgerTrialBalanceTmp.AmountCredit;
        _TrialBalance.EndingBalance = _ledgerTrialBalanceTmp.EndingBalance;
        _TrialBalance.NetChange = _ledgerTrialBalanceTmp.NetChange;
        _TrialBalance.insert();
    }
}

The code works but doesn’t seem to pull the exact data displayed in the Trial Balance feature, some periods have the wrong Closing Balances, Debit amount and Credit, so when I check in the Trial Balance report the data looks correct but not in my table. Can someone point me in the right direction or suggest a better approach to make sure I'm retrieving the exact trial balance data?
  • Suggested answer
    Raj Borad Profile Picture
    1,588 on at
    Hi Mario,
    I have answer in the below thread. you can change your way and get some logic from there and the data as per the Trial Balance into your custom table.
     
    Thanks & Regards,
    Raj D Borad
  • Verified answer
    Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at

    The form is pretty basic, so I expect the method to return the same values. Are you sure you are calling it with the exact same values in contract as the form?

    One thing that comes to mind is that your code might be forcing the use of the old trial balance calculation and not considering the feature for the optimized trial balance calculation. I'd recommend you use LedgerTrialBalanceTmp::calculateBalances_V2 instead of using LedgerTrialBalanceDP directly.

  • Mario C Profile Picture
    90 on at

    Hello Jonas,

    Thank you for your suggestion, you were right! I used the calculateBalances_V2 method directly and passed all the parameters instead of using the DP, and it worked like a charm! I appreciate your help!

    Best,
    Mario C.

Under review

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

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 495 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 432 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 366

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans