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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

after SysDatabaseTransDelete the trail balance is still with transactions

(0) ShareShare
ReportReport
Posted on by 2,475

Salam Allkom ;

 I make test transaction then I user SysDatabaseTransDelete  to delete all transaction ,

all transactions deleted in AP AR  INV  , but when i back to check the account is still the balance with effected, Now I need to delete account Debit credit ending balance, to go live with live data .

thanks in advanc e.

 

 

*This post is locked for comments

I have the same question (0)
  • Juliuz Profile Picture
    115 on at

    I have the same issue here.

    What i have found so far is that sysdatabasetransdelete cannot delete GeneralJournalEntry and GeneralJournalAccountEntry, i'm still testing but it seems that if you delete manually this tables (in a one company enviroment because this is a shared table), and deleting and recreating the focus balances may help. i haven't tested this completely but it seems that this is where AX takes the data to sum up the DimensionFocusBalance table (this is where the balances are stored and updated every time you post a transaction)

  • Suggested answer
    Mohamad-Al Shami Profile Picture
    30 on at

    Hello,

    if you are using AX 2012  First make sure that you update sysdatabasetransdelete to include

    case TableGroup::TransactionHeader:

    case TableGroup::TransactionLine:

    To delete GL trans delete the following tables:

    GeneralJournalAccountEntry

    GeneralJournalEntry

    LedgerEntryJournal

    LedgerEntry

    Ledgerjournaltrans

    Ledgerjournaltable

    Good Luck

  • Community Member Profile Picture
    on at

    You need to handle LEDGERJOURNALTABLE differently from other tables to clear out the shared tables (GeneralJournalAccountEntry, GeneralJournalEntry, LedgerEntryJournal, LedgerEntry which are the sources of the Trial balance form):

    1) add a new method to handle LEDGERJOURNALTABLE:

    private void deleteLedgerJournalTables() /* 28Nov12-Admin */
    {

        GeneralJournalEntry         GJEntry;
        GeneralJournalAccountEntry  GJAEntry;
        LedgerJournalTable          ledgerjournalTable;
        LedgerEntryJournal          ledgerEntryJournal;

        ttsBegin;
        while select forupdate LedgerJournalTable
        {
            while select forUpdate ledgerEntryJournal
                where ledgerEntryJournal.JournalNumber == ledgerjournalTable.JournalNum
                //&&    ledgerEntryJournal.dataAreaId == ledgerjournalTable.dataAreaId
            {
                while select forUpdate GJEntry
                    where GJEntry.LedgerEntryJournal == ledgerEntryJournal.RecId
                {
                    //info(strFmt('Deleting %1 ',GJEntry.JournalNumber));
                    delete_from GJAEntry
                        where GJAEntry.GeneralJournalEntry == GJEntry.RecId;

                    GJEntry.delete();
                }
                ledgerEntryJournal.delete();
            }
            LedgerJournalTable.delete();
        }
        ttsCommit;
    }

     

     

    2) Modify the 'handleTransTable()' method to call the above method

    void handleTransTable(SysDictTable sysDictTable)
    {
        switch(sysDictTable.id())
        {
            case tablenum(CustCollectionLetterLine):
            case tablenum(InventDim):
            case tablenum(DocuRef):
            case tablenum(DirPartyRelationship) :

                break;
            case tablenum(LedgerJournalTable) : /* 28Nov12-Admin */
                this.deleteLedgerJournalTables();
                break;


            default:
                this.deleteTable(sysDictTable);
                break;
        }
    }

     

    3) you may have to modify the 'deleteVoucher()' method in the 'LedgerJournalTrans' table to skip over releasing non-existing voucher numbers

    public server void deleteVoucher(Voucher _voucher = this.Voucher)
    {
        LedgerJournalTable  ledgerJournalTable = LedgerJournalTable::find(this.JournalNum);

        if (! ledgerJournalTable.Posted && !this.Transferred)
        {
            if (_voucher && ! LedgerJournalTrans::existTransMinusThis(this.JournalNum, _voucher, this.RecId))
            {
                if (this.checkVoucherNotUsed(ledgerJournalTable, _voucher))
                {
                    if (this.checkVoucherNotUsedDataSource(_voucher))
                    {
                        // replace the voucher number so it can be re-used
                        if (ledgerJournalTable.NumberSequenceTable) /* 28Nov12-Admin */
                            NumberSeq::releaseNumber(ledgerJournalTable.NumberSequenceTable, _voucher);

                        if (this.Voucher == _voucher)
                        {
                            // delete voucher template record if exists and the voucher on the line is not being changed
                            LedgerJournalTransVoucherTemplate::deleteForJournalOrVoucher(this.JournalNum, _voucher);
                        }
                    }
                }
            }
        }
    }

    4) after running 'SysDatabaseTransDelete', rebuild balances for the Financial dimension sets (General Ledger\Setup\Financial Dimensions\Financial dimension sets)

     

    If you still have non-zero amounts in the Trial balance then you must manually remove the 'left-over' rows in the shared tables (results of your previous executions of the 'SysDatabaseTransDelete'). Identify these entries in the 'LedgerEntryJournal' table then use the following job to clear them:

    static void tg_deleteTables(Args _args)
    {
        GeneralJournalEntry         GJEntry;
        GeneralJournalAccountEntry  GJAEntry;
        LedgerJournalTable          ledgerjournalTable;
        LedgerEntryJournal          ledgerEntryJournal;

        ttsBegin;
            while select forUpdate ledgerEntryJournal
                where ledgerEntryJournal.JournalNumber like 'clau*'   //<<<< USE this to pickup the entries to be removed.
                //&&    ledgerEntryJournal.dataAreaId == ledgerjournalTable.dataAreaId
            {
                while select forUpdate GJEntry
                    where GJEntry.LedgerEntryJournal == ledgerEntryJournal.RecId
                {
                    //info(strFmt('Deleting %1 ',GJEntry.JournalNumber));
                    delete_from GJAEntry
                        where GJAEntry.GeneralJournalEntry == GJEntry.RecId;

                    GJEntry.delete();
                }
                ledgerEntryJournal.delete();
            }

        ttsCommit;
        info('completed');
    }

     

    Good luck.

  • Juliuz Profile Picture
    115 on at

    I finally was able to find the exact recid on the GeneralJournalAccountEntry where the last transaction before executing the SysDataBaseTransDelete class using the createddatetime on the GeneralJournalEntry

    So based on that i deleted GeneralJournalAccountEntry and GeneralJournalEntry records and the subledger records related to them.

    After that, it was needed to delete dimension focuses an re create them in order to clean the balances on the trial balance.

    In that enviroment i had only one company so everything was straight forward, but if you want to delete ledger records for one company you need to join the SubledgerVoucherGeneralJournalEntry and filter the voucherdataareaid field in order to delete only the desired records.

  • Suggested answer
    Community Member Profile Picture
    on at

    Khaled,

    You can clear the TB balances through AX directly; you don't need to write any code for that. Just go to: General ledger-->Setup-->Financial dimensions-->Financial dimension sets. Select the dimension one by one and click on either "Rebuild balances" or "Update balances". Both should do the same; reset your balances for all accounts and dimensions to zero provided you have deleted all the transactions from the system, which I guess you already did that through sysDatabaseTransDelete class.

    Happy DAXing!

  • Syed Shabab Mujtaba Profile Picture
    278 on at

    @ Khaled,

    True produtc solution....very very thanks... i was also facing same problem...your solution solved it in 1 sec...

  • Juliuz Profile Picture
    115 on at

    Problem is that when you use sysdatabasetransdelete, the process deletes only tables that are not shared between companies, leaving records in the generaljournalaccountentry table.

    So no matter how many time you push the rebuild balances button, for some reason the process takes into account those records, it may seem to clean the balances at first, but once you start posting transaction you may notice that some accounts start showing incorrect balances.

    Already had a suppot ticket with MS and they said that sysdatabasetransdelete is not fully supported in AX 2012, althoug deleting the  tables solved my problem

  • Syed Shabab Mujtaba Profile Picture
    278 on at

    Hi Juliuz,

    I have deleted all the transactions, but only ledgerbalances were available. Doing balances zero by solution of Khalid is showing ledger balances zero balances zero. Let me know there will be no proper balances if we will do ledger postings.

  • Juliuz Profile Picture
    115 on at

    Firs time i did it, i had to delete and re create the focus balances/ initialize balances.

    So just to be sure i'd do that.

  • ewills Profile Picture
    5,990 on at

    Hi Bilal and everyone, what is the best way to delete all transactions, journal/voucher entries in AX 2012? your answer is much appreciated.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans