web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Auto Posting Ledger Journal Take a Long Time

(0) ShareShare
ReportReport
Posted on by 563

Dear Experts,

I'm beginner develop dynamic ax, now creating auto post journal through X++ by using AxLedgerJournalTableClass and AxLedgerJournalTransClass

My data saved on my temporary table, then successfully create 1 journal with 1459 lines on 5 minute

Could I tune up my code to make it faster?

Here is Server Specification :

Processor     :  Intel i3 2.40Ghz

RAM             : 8 GB

And here is my code 

static void TestAutoPost(Args _args)
{
    AxLedgerJournalTable    journalTableClass;
    AxLedgerJournalTrans    journalTransClass;

    container ledgerDimension;
    container defaultDimension;

    VDI_LedgerJournal_Temp ledgerJournalTemp;
    LedgerJournalTable      ledgerJournalTable;
    LedgerJournalCheckPost  ledgerJournalCheckPost;
    int no = 1;

    DialogButton autopost;
    ;
    autopost = Box::yesNo("Do you want to auto post all journal?",DialogButton::Yes,"Auto Post Question");
    try{
        journalTableClass   = new AxLedgerJournalTable();

        select ledgerJournalTemp group by ledgerJournalTemp.JournalName,ledgerJournalTemp.Description;

        journalTableClass.parmJournalName(ledgerJournalTemp.JournalName);
        journalTableClass.parmName(ledgerJournalTemp.Description);
        journalTableClass.save();

        while
        select ledgerJournalTemp
        {
            journalTransClass   = new AxLedgerJournalTrans();

            journalTransClass.parmJournalNum(journalTableClass.ledgerJournalTable().JournalNum);
            journalTransClass.parmTxt(ledgerJournalTemp.LineDescription);
            journalTransClass.parmTransDate(ledgerJournalTemp.TransactionDate);
            journalTransClass.parmCurrencyCode(ledgerJournalTemp.CurrencyCode);
            journalTransClass.parmAmountCurDebit(ledgerJournalTemp.DebitAmount);
            journalTransClass.parmAmountCurCredit(ledgerJournalTemp.CreditAmount);
            defaultDimension = [1,"TransactionType",ledgerJournalTemp.LedgerDimension];
            journalTransClass.parmDefaultDimension(AxdDimensionUtil::getDimensionAttributeValueSetId(defaultDimension));
            journalTransClass.parmOffsetDefaultDimension(AxdDimensionUtil::getDimensionAttributeValueSetId(defaultDimension));
            journalTransClass.parmAccountType(LedgerJournalACType::Ledger);
            ledgerDimension = [ledgerJournalTemp.AccountNum+"-"+ledgerJournalTemp.LedgerDimension,ledgerJournalTemp.AccountNum,1,"TransactionType",ledgerJournalTemp.LedgerDimension];
            journalTransClass.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(ledgerDimension));
            journalTransClass.parmOffsetLedgerDimension(DimensionStorage::getDynamicAccount(ledgerJournalTemp.OffsetLedgerDimension, LedgerJournalACType::Bank) );
            journalTransClass.parmOffsetAccountType(LedgerJournalACType::Bank);
            journalTransClass.parmDocumentNum(ledgerJournalTemp.Document);
            journalTransClass.save();
            no++;
        }

        if(autopost == DialogButton::Yes){
            ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTableClass.ledgerJournalTable(),NoYes::Yes);
            ledgerJournalCheckPost.run();
        }
        info(strFmt("Journal has been saved with %1 lines",no));
    }
    catch(Exception::Error){
        error(strFmt("Error at line %1",no));
    }
}


*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    299,702 Super User 2025 Season 2 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    Hi Tahta,

    What is exactly happening when you fill the temporary table? Are you trying to copy standard available functionality? See this page: Post multiple journals [AX 2012]. The journals can be posted using the batch framework, which will also speed up the process.

  • Community Member Profile Picture
    on at
    RE: Auto Posting Ledger Journal Take a Long Time

    Hi!

    You can divide your journal (for example) into several journals (for example 1 journal 100 lines) in different transactions (and parallel post).

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    The correct solution is what Crispin has suggested in case you only want to redesign your job.

    One piece I would add is that once you move the code server-side, make sure there are no user interactions in that piece (box class).

    However, consider other solutions as well like mentioned by the others. If you are importing/creating new journals, you may use the Data Import eXport Framework to do that, and process the created journal by a batch.

  • Bintang Profile Picture
    563 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    Hi all, thank for your respond

    I make it into a class method

    It takes 3 minute 14 second, faster than before

    any idea to make it faster?

    If it possible , I want it under 1 minute

    thank you

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    You must capture an AX Trace for the code running on the AOS server, then analyze it using the AX Trace Parser Tool to see if it is the code, or if it is the SQL statement that is running slow. Or maybe it is running fast for a single row, but loops a million times which makes the total execution time high. You can only check it by verifying what is in the trace, and take action on it.

    See the Microsoft blog article about the tool:

    blogs.msdn.microsoft.com/.../dynamics-ax-trace-parser-part-3

    Also you should do an SQL Query Profiler trace as well for your database server while only your query is running to minimize noise, and then check the query plans executed for the report's select statement, to see if there are correct covering indexes, there are no index scans, and so on.

  • Bintang Profile Picture
    563 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    I don't have access to download that tool

  • Bintang Profile Picture
    563 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    I did, and change it with firstonly but not significantly speed up performance

    I try to recreate code using service's classes : LedgerGeneralJournalService, LedgerGeneralJournal_LedgerJournalTable, LedgerGeneralJournal_LedgerJournalTrans, etc

    What do you think about it? Is it could speed it up?

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Auto Posting Ledger Journal Take a Long Time

    You do not need to download it, the Trace parser tool is part of the AX installer DVD, that you could deploy. Use that explained in the blog article to collect information and analyze what is exactly slow in your case.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
AlissonGodoy Profile Picture

AlissonGodoy 2

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans