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