/ Microsoft / Create general journal using X++ in D365FO

Create general journal using X++ in D365FO

Learn, share and spread knowledge

General journal can be created using X++ code. This code which I am sharing in this article helps you to create general journal using X++ in D365FO.

In Microsoft Dynamics 365 for Finance and Operations, creating the general journal through X++ is different than creating in Microsoft Dynamics AX 2012. In D365FO, there is an abstract class named as MCRLedgerJournal, which you have to inherit and implement by yourselves.

I have created the MCRLedgerJournal_Moeen class which inherits (extends) the abstract class. To see how to implement the abstract class, you can get the example by viewing MCRLedgerJournal_CustPayment, MCRLedgerJournal_Daily and MCRLedgerJournal_Payment etc. classes.

In our case, I have copied the MCRLedgerJournal_Daily class and pasted it in my own class (MCRLedgerJournal_Moeen) and modifies it according to my requirements. Apart from this, you can also use the MCRLedgerJournal_Daily class directly if you don’t want to implement your own class.

Following is the code to implement the MCRLedgerJournal abstract class.

class MCRLedgerJournal_Moeen extends MCRLedgerJournal
    public LedgerJournalTrans createLedgerJournalTrans(AmountCurCredit _amtCurCredit, AmountCurDebit _amtCurDebit, LedgerJournalACType _ledgerJournalACType = LedgerJournalACType::Ledger)
        LedgerJournalTrans ledgerJournalTrans;

        // Validate the input to the ledger journal trans and ensure that a ledgerjournaltable
        // exists before creating the ledger journalTrans.
        if (this.validateInputLedgerJourTrans(_amtCurCredit, _amtCurDebit)
            && ledgerJournalTable.RecId != 0)

            ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
            ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
            ledgerJournalTrans.LedgerDimension = ledgerAccount;
            ledgerJournalTrans.OffsetAccountType = ledgerOffsetAccountType;
            ledgerJournalTrans.OffsetLedgerDimension = ledgerOffsetAccount;
            ledgerJournalTrans.Txt = transTxt;
            ledgerJournalTrans.CurrencyCode = curCode;
            ledgerJournalTrans.ExchRate = exchRate;
            ledgerJournalTrans.Approver = approver;
            ledgerJournalTrans.Approved = approved;
            // Bank reconciliation specific.
            ledgerJournalTrans.MCRCCGeneralLedgerId = MCRCCGeneralLedgerId;
            ledgerJournalTrans.Due = dueDate;
            ledgerJournalTrans.LineNum = lineNum;
            ledgerJournalTrans.AccountType = ledgerAccountType;
            ledgerJournalTrans.Voucher = voucherNum;
            ledgerJournalTrans.PaymReference = paymReference;
            ledgerJournalTrans.BankTransType = bankTransType;
            ledgerJournalTrans.PaymMode = paymentMode;
            // Add the ref paym id and the paym order id to ledger journal trans.
            ledgerJournalTrans.MCRRefPaymID = MCRRefPaymID;
            ledgerJournalTrans.MCRPaymOrderId = MCRPaymOrderID;

            if (_amtCurCredit != 0)
                ledgerJournalTrans.AmountCurCredit = _amtCurCredit;
            if (_amtCurDebit != 0)
                ledgerJournalTrans.AmountCurDebit = _amtCurDebit;

            throw error("@MCR35845");

        return ledgerJournalTrans;

    /// <summary>
    /// Creates a new instance of the <c>MCRLedgerJournal_Daily</c> class.
    /// </summary>
    /// <param name="_ledgerJournalType">
    /// The type of journal to be used in the instantiation of this class.
    /// </param>
    /// <param name="_journalName">
    /// The name of the journal to be used in the instantiation of this
    /// class; optional.
    /// </param>
    public void new(LedgerJournalType _ledgerJournalType, LedgerJournalNameId _journalName="")
        super(_ledgerJournalType, _journalName);

    protected boolean validateInputLedgerJourTrans(AmountCur _amtCurCredit, AmountCur _amtCurDebit)
        boolean ret;

        ret = super(_amtCurCredit, _amtCurDebit);
        if (ret)
            if (ledgerAccount == 0)
                throw error(strFmt("@MCR36388"));
        return ret;


Now, the next step is to create the General journal using the above created class. I have written a job which creates the General journal using X++. See the following code:

class GenerateGeneralJournalJob
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
        MCRLedgerJournal        journalTable;
        LedgerJournalTable      ledgerJournalTable;
        Counter                 recordsInserted;

        //Creates the journal header table
        journalTable = new MCRLedgerJournal_Moeen(LedgerJournalType::Daily);        
        ledgerJournalTable = journalTable.createLedgerJournalTable();

        //I am creating two lines to balance out each other.

        // creates a new line in general journal
        journalTable.parmLedgerAccount(LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber("V-000001",LedgerJournalACType::Vend)); //You need to use the vendor account as per your environment's data.

        // creates a new line in general journal
        //Using RecId of Ledger Dimension, you need to enter the RecId as per your environment's data.


So, in this way you can create general journal using X++ in D365FO. Moreover, if this helps you, please Like, Comment and Share to help other people.

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

Blog: Click here

YouTube: Click here

GitHub: Click here

The secret of getting ahead is getting started. – Mark Twain


Send Us A Message Here

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