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 :
Microsoft Dynamics AX (Archived)

Automating "Load ledger transaction" functionality in X++

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    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

  • Teemu Miettinen Profile Picture
    65 on at

    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.

  • Verified answer
    Teemu Miettinen Profile Picture
    65 on at

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

  • Suggested answer
    Suheng Sun Profile Picture
    10 on at

    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!

  • Teemu Miettinen Profile Picture
    65 on at

    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;

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
Basit Profile Picture

Basit 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans