Skip to main content

Notifications

DAX 2012 Remove reservations and markings from a sales order

Some friends of me have asked how to remove reservations and markings on a sales order. Going through line by line can be time consuming and they wanted to know how this could be solved by a single “click”.

 

static void Tutorial_UnreserveSalesTable(Args _args)
{
    InventTrans             inventTrans;
    InventTransOrigin       inventTransOrigin;
    SalesLine               salesLine;
    InventMovement          inventMovement;
    InventUpd_Reservation   inventUpd_Reservation ;
    SalesId                 SalesId = "001260";//<--- Send/get sales id here

    // Remove reservations and markings on a reserved salesorder
    while select inventTrans
        where inventTrans.StatusReceipt                == StatusReceipt::None
           && (inventTrans.StatusIssue                 == StatusIssue::ReservPhysical 
           ||  inventTrans.StatusIssue                 == StatusIssue::ReservOrdered)
        exists join inventTransOrigin 
            where   inventTransOrigin.RecId            == inventTrans.InventTransOrigin
        exists join salesLine 
            where   salesLine.InventTransId            == inventTransOrigin.InventTransId                    
                &&  SalesLine.SalesId                  == SalesId    
    {
            if (inventTrans.MarkingRefInventTransOrigin)
            {
                InventTransOrigin::deleteMarking(inventTrans.MarkingRefInventTransOrigin, inventTrans.InventTransOrigin, -inventTrans.Qty, true);
                InventTransOrigin::deleteMarking(inventTrans.InventTransOrigin, inventTrans.MarkingRefInventTransOrigin, inventTrans.Qty, true);
            }

            if (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered)
            {                
                Inventmovement = inventTrans.inventmovement(true); 
                inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(), -1 * inventTrans.Qty, false); 
                inventUpd_Reservation.updatenow(); 
            }
    }
}

The next step would be to create a class, so that it can be performed in CIL, and some code that refreshes the sales order for the end-user.


Comments

*This post is locked for comments