Search code examples
axaptax++dynamics-ax-2009

Programmatically Cancel SalesOrders in AX


I would like to programmatically cancel all SalesOrders in AX2009 that have status of BackOrder and are less than a specific date.


Solution

  • I managed to do this by running the following Job

    static void SalesOrderUpdate(Args _args)
    {
        SalesTable          salesTable;
        SalesLine           salesLine;
        int i;
        ;
        changecompany ('10')
        {
            ttsBegin;    
            while select forUpdate salesTable 
                where salesTable.SalesStatus == SalesStatus::Backorder
                &&    salesTable.ReceiptDateRequested  <= 31\12\2016
                &&    salesTable.ShippingDateRequested <= 31\12\2016
                join forUpdate salesLine
                where salesLine.SalesId == salesTable.SalesId
            {
                i++;    
                salesLine.RemainSalesPhysical = 0;
                salesLine.RemainInventPhysical = 0;
                salesLine.update();    
            }
            ttsCommit;    
        }
        info(int2Str(i));    
    }