AX2009 Restore deleted sales table without restoring sales line

TL;DR: Restore deleted sales table without restoring sales line with X++

Problem

There are sometimes constelations where the user deletes the header of the sales order (sales table), but AX2009 will not delete the appropiate sales line entries. So we end up with open sales line entries without the header. That causes some problems when posting invoices and so on.

Solution

You could try to cancel the entries directly over AOT in the databrowser. But I went with the approach to restore the header of the salesorder from SalesTableDelete without restoring the sales lines. And after that the user can manually cancel the sales order.

AX2009 Job

static void down1_RestoreSalesTableWithoutSalesLine(Args _args)
{
    SalesTableDelete    ltabsalesTableDelete;
    SalesTable          ltabsalesTable;
    ;
    ltabsalesTableDelete = SalesTableDelete::find('A103990087', true);
    ttsbegin;
    switch (ltabsalesTableDelete.Cancelled)
    {
        case Voided::Voided :
            ltabsalesTable  = conpeek(ltabsalesTableDelete.SalesTable, 1);
            ltabsalesTable.insert();
            ltabsalesTableDelete.delete();
            break;
   }
   ttscommit;
}
Originally published July 27, 2023 | View revision history

If you enjoyed this post, you might also enjoy:

downarowiczd

MS Dynamics AX / D365 FO developer with experience in administration, developing new and adjusting the existing solutions in the Dynamics AX 2009, AX 2012, D365 FO. Ability to support all phases of implementation of project, starting with design, development, final deployment and administration. Responsible team member always looking for new challenges with experience from international projects in Austria, Germany and Switzerland. Experience in implementation of external service to MS Dynamcis AX / D365, like cash registers and warehouse automations. More about the author →