/ Microsoft / Get total debit and credit against voucher in x++

Get total debit and credit against voucher in x++

Learn, share and spread knowledge

In Microsoft Dynamics 365 for Finance and Operations and Microsoft Dynamics AX 2012, it is really difficult to get total debit and credit against voucher of payment journal shown as follows:

Total debit and credit against voucher

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:

//Author:   Moeen Ahmed Sultan
//Email:    moeenahmedsultan@gmail.com
//Tel:      +92 321 458 9595

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)));

In this way you can get voucher debit and voucher credit values using x++. Moreover, if this helps you, please Like, Comment and Share to help other people.

Note: I have tested this code is tested in D365FO but not in AX 2012.

If you found any ambiguity or a better solution, please feel free to ask.

Download code: Click here

Blog: Click here

YouTube: Click here

GitHub: Click here

I have got a dream that’s worth more than my sleep. – Eric Thomas

0 POST COMMENT

Send Us A Message Here

Your email address will not be published. Required fields are marked *