Tuesday, March 8, 2022

D365 F&O Get Total debit and credit against voucher x++

  

Voucher debit and credit fields on the form are not having the permanent table in back-end. Moreover, these fields are using display methods written in the data source. And, these display methods are using LedgerJournalEngine class to get these values. So, I am sharing the following code for all of you:






LedgerJournalEngine ledgerJournalEngine;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTable  ledgerJournalTable;

ledgerJournalTable.clear();
ledgerJournalTrans.clear();
                
select ledgerJournalTrans
     where ledgerJournalTrans.Voucher == "VOUCHER NUMBER"; //Add voucher number in the double quotes against which you want to get total debit and credit.
ledgerJournalEngine = new ledgerJournalEngine();
ledgerJournalTable = ledgerJournalTable::find(ledgerJournalTrans.JournalNum);
ledgerJournalEngine.newJournalActive(ledgerJournalTable,true);
info(strFmt("%1 - %2", ledgerJournalEngine.voucherDebit(ledgerJournalTrans), ledgerJournalEngine.voucherCredit(ledgerJournalTrans)));






No comments:

Post a Comment