Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Automating "Load ledger transaction" functionality in X++

Posted on by 65

I need advice how to automate the General Ledgers "Load ledger transaction" process in X++. 

(General Journal > Lines > Functions > Load ledger transactions) with params: 

  • Voucher: "New voucher number per voucher"
  • Invert sign = checked
  • General journal entry = VouhcerNumber (this I receive from earlier process)

I have created an PostEventHandler which will perform this operation for the voucher it is handling in the project's elimination process based on the checkbox selection. In the EventHandler I have created a new Ledger journal using the AXLedgerJournalTable class and now I need to create the inverted transaction lines for the voucher and post it.

I've been trying to mimic of the Load process starting from the LedgerJournaGetTrans.main(), but I end up recreating about everything in it in the event handler and the code is getting quite messy. Is there better way to do this? Can I use some other classes like TransactionReversal_Ledger for this?

*This post is locked for comments

  • Teemu Miettinen Profile Picture
    Teemu Miettinen 65 on at
    RE: Automating "Load ledger transaction" functionality in X++

    Hey,

    Sorry about delay on the reply as I was in summer holidays when you posted this request.

    In iNNParmReverseSign(NoYes::Yes)  -method I just SET -method for the parameter, because I cannot access it directly as the class is Private.

    If I remember it correctly it was something like this:

    Public class iNNParmReverseSign(NoYes _reversing)

    {

    // set the new value

    ReverseSign = _reversesing;

    }

  • Suggested answer
    Suheng Sun Profile Picture
    Suheng Sun 10 on at
    RE: Automating "Load ledger transaction" functionality in X++

    Hi Teemu, Thank you to share this blog. Can you share the method "iNNParmReverseSign" and others? because they are not system method. Thank you very much!

  • Verified answer
    Teemu Miettinen Profile Picture
    Teemu Miettinen 65 on at
    RE: Automating "Load ledger transaction" functionality in X++

    Got it solved my self. Heres my succesfully tested solution. I did not post new parm-classes as those are trivial.

    public static void OnActionProjControlPeriodEli_Handler(XppPrePostArgs _xppPrePostArgs)
    {
        Object                      object;
        ProjControlPeriodEliminate  projControlPeriodEliminate;

        ProjControlPeriodTable      projControlPeriodTable;
        AxLedgerJournalTable        axLedgerJournalTable ;
        LedgerJournalGetTrans       ledgerJournalGetTrans;
        QueryRun                    queryRun;
        QueryBuildDataSource        queryDataSource;
        QueryBuildRange             queryBuildRange;
        ledgerJournalCheckPost      ledgerJournalCheckPost;

        // Get the dialog settings
        object = _xppPrePostArgs.getThis();

        if(object is projControlPeriod)
        {
            projControlPeriodEliminate = object as projControlPeriodEliminate;

            // If user needs to reverse the voucher in elimination.
            if(ProjControlPeriodEliminate.iNNParmPostEstimateReversalVoucher() == NoYes::Yes)
            {
                // Creates a new ledger journal
                axLedgerJournalTable = new AxLedgerJournalTable();
                axLedgerJournalTable.parmJournalName(projControlPeriodEliminate.iNNParmLedgerJournalNameId());
                axLedgerJournalTable.save();

                info(strFmt("A new ledger journal %1 created with journal name %2", axLedgerJournalTable.ledgerJournalTable().JournalNum,

    projControlPeriodEliminate.iNNParmLedgerJournalNameId()));

                
                // Only posted project lines needs to be reversed
                while select projControlPeriodTable
                    where projControlPeriodTable.PeriodStatus == projControlPeriodStatus::Posted
                        && projControlPeriodTable.ProjId == projControlPeriodEliminate.parmProjWIPProjId()
                {
                    // Load the invert transaction
                    ledgerJournalGetTrans = LedgerJournalGetTrans::INNnewLedgerJournalTable(axLedgerJournalTable.ledgerJournalTable());

                    // Override parameters
                    ledgerJournalGetTrans.iNNParmReverseSign(NoYes::Yes); // We want always to reverse the journals

             // We want always create new vouchers for inverted

             ledgerJournalGetTrans.iNNParmLedgerGetVoucherMethod(LedgerGetVoucherMethod::NewPrVoucher);

                    // We need to build the dialog query by hand
                    queryRun        = ledgerJournalGetTrans.iNNParmQueryRun();
                    queryDataSource = queryRun.query().dataSourceTable(tablenum(GeneralJournalEntry));
                    queryBuildRange = queryDataSource.addRange(fieldNum(GeneralJournalEntry, subLedgerVoucher));
                    queryBuildRange.value(queryValue(projControlPeriodTable.VoucherPosted)); // We need to reverse the voucher in hand.

                    ledgerJournalGetTrans.run();

                    info(strFmt("Inverted lines created against voucher %1 in journal %2.",projControlPeriodTable.VoucherPosted ,

    LedgerJournalGetTrans.parmLedgerJournalId()));

                }
               
                // Posting the lines
                if(LedgerJournalGetTrans)
                {
                    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(axLedgerJournalTable.ledgerJournalTable(), NoYes::Yes);
                    ledgerJournalCheckPost.run();
                }
            }
        }
    }

    AND THE NEW CONSTRUCT CLASS:

    // A construct class without dialog handling.
    public static LedgerJournalGetTrans iNNNewLedgerJournalTable(LedgerJournalTable _ledgerJournalTable)
    {
        LedgerJournalGetTrans   ledgerJournalGetTrans;

        ledgerJournalGetTrans = new LedgerJournalGetTrans();
        ledgerJournalGetTrans.init();

        ledgerJournalGetTrans.parmLedgerJournalId(_ledgerJournalTable.JournalNum);

        return ledgerJournalGetTrans;
    }

  • Teemu Miettinen Profile Picture
    Teemu Miettinen 65 on at
    RE: Automating "Load ledger transaction" functionality in X++

    Thanks Ludwig. First time using this, so was not sure how to use the tags. Tags corrected now. Our Customer is using parts of the AX as a service for their own customers so this is not normal AX-business case.

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Automating "Load ledger transaction" functionality in X++

    Hi Teemu, What is the Business reason for the adjustment you want to make? Probably add /Change tags if possible as the development experts in the community might not easily find your post if you classify it as "financial Management" question. Ludwig

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans