Cancel picking for all items and remove reservation using X++


some times when pick some items and you go to pick list registration to update the picked items some error occur and you need to cancel all the picked items and  remove reservation to pick the items again  try this code it will helping : 

void clicked()
{
WMSOrderTrans _WMSOrderTrans;
InventTrans invtrans;
InventDim invdim;
InventDim _invdim;
WMSPickingRoute _WMSPickingRoute;

int summ=0;
str status;

///////////////////////////////////


SalesLine _salesLine;
InventQty _InventQty;
InventDim _inventDim;
SalesTable _salsetable;
InventTable _inventtable;
WMSOrder _wms;
;

  //cancel
    /////////////////////////////////////////////////////////
// box::info(WMSPickingRoute.pickingRouteID);
  if (Box::yesNo(strfmt("Are You Sure You Want To Cancel this Picking Rout( "+WMSPickingRoute.pickingRouteID+" )", curext()),DialogButton::No))
  {
if(WMSPickingRoute.expeditionStatus==WMSExpeditionStatus::Activated)
{
while select forupdate _WMSOrderTrans where _WMSOrderTrans.routeId==WMSPickingRoute.pickingRouteID
{
ttsbegin;
_WMSOrderTrans.cancel();

ttscommit;
 //_WMSOrderTrans.update();
}

//remove reservation
   select  forupdate invtrans
            where
               ( invtrans.TransRefId==WMSPickingRoute.transRefId);
 //   box::info("first");
   while (invtrans)
   {
       if(invtrans.StatusIssue ==StatusIssue::ReservPhysical)
       {

     //  Box::info("OK");
       select forupdate _WMSOrderTrans where _WMSOrderTrans.itemId==invtrans.ItemId&&_WMSOrderTrans.inventTransRefId==invtrans.TransRefId&&(_WMSOrderTrans.expeditionStatus==WMSExpeditionStatus::Cancelled ||
       _WMSOrderTrans.expeditionStatus==WMSExpeditionStatus::Complete);
       if(_WMSOrderTrans)
       {
/*
            invtrans.Qty=0;
            invtrans.StatusIssue=StatusIssue::None;
            invtrans.update();
            */
            _WMSOrderTrans.isReserved=noyes::No;
             ttsbegin;
            _WMSOrderTrans.update();
             invTrans.StatusIssue =statusissue::OnOrder;
            ttscommit;
           // invtrans.delete();
            summ++;
            }
       }
             next invtrans;
   }
   WMSPickingRoute_ds.executeQuery();
 //  WMSOrderTrans_ds.refresh();
   info("Done Cancel all lines");
   /////////////////////////////////////////////////////////
   }
   else
   warning("This order is already "+enum2str(WMSPickingRoute.expeditionStatus));
   }

}

Comments

Popular Posts