Cancel transfer/sales order picks

Here is an example of X++ code, which can be used to cancel existing transfer/sales order picks:

    void cancelPreviousPicks(SalesId _salesId)
    {
        SalesLine           salesLine;
        wmsOrderTrans       wmsOrderTrans,
                            wmsOrderTransNew;
        InventTrans         inventTransCancel;
        InventTransOrigin   inventTransOriginCancel;

        // select forupdate is required by standard unpick logic
        while select forupdate wmsOrderTrans
            //join inventTransferLine
            //    where inventTransferLine.TransferId == _transferId
            join salesLine
                where salesLine.SalesId             == _salesId
                    &&wmsOrderTrans.inventTransId   == salesLine.InventTransId
                    &&wmsOrderTrans.expeditionStatus== WMSExpeditionStatus::Complete
        {

            select sum(qty), sum(PdsCWQty)
                from inventTransCancel
                join inventTransOriginCancel
                    where  inventTransOriginCancel.InventTransId    == wmsOrderTrans.inventTransId
                        && inventTransOriginCancel.RecId            == inventTransCancel.inventTransOrigin
                        && InventTransCancel.StatusIssue            == statusIssue::Picked
                        && InventTransCancel.PickingRouteID         == wmsOrderTrans.RouteId;

            // Unpick previous picks if not delivered
            if (abs(InventTransCancel.qty) >= wmsOrderTrans.qty)
            {
                wmsOrderTrans.wmsOrderTransType().unPick(
                    wmsOrderTrans.qty,
                    wmsOrderTrans.inventDim(),
                    NoYes::Yes,
                    wmsOrderTrans.PdsCWQty
                );
            }
            // If there is delivered quantity then unpick as much as possible that has not been delivered
            else if (InventTransCancel.qty < 0  && abs(InventTransCancel.qty) < wmsOrderTrans.qty)
            {
                wmsOrderTransNew = wmsOrderTrans.split(abs(InventTransCancel.qty), abs(InventTransCancel.PdsCWQty));
                wmsOrderTransNew.wmsOrderTransType().unPick(
                    abs(InventTransCancel.qty),
                    wmsOrderTrans.inventDim(),
                    NoYes::Yes,
                    wmsOrderTrans.PdsCWQty
                );
            }
        }
    }


Support The Author

If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee


Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags