Cancel Post packing slip from all Shipments in D365 F&O through X++

 Hi Viewers,

To Cancel Post packing slip for Shipments. we first have to cancel the Packing slip, reverse the shipment, and then reopen the container.


To Cancel Post packing slip:

 WHSLoadTableCustPackingSlipJour loadCustJour;
 CustPackingSlipJour             custJour;
  WHSLoadTable        loadTable;

      loadTable = whsshipmenttable::find(ShipmentID).whsLoadTable();

     while select custJour
         where custJour.Qty
         exists join loadCustJour
             where loadCustJour.WHSLoadTableLoadId       == loadTable.LoadId
             &&    loadCustJour.WHSLoadTableDataAreaId   == loadTable.DataAreaId
             &&    loadCustJour.CustPackingSlipJourRecId == custJour.RecId
     {
         Args args = new Args();
         args.record(custJour);
         args.parmEnum(enum2int(DocumentStatus::PackingSlip));
         new MenuFunction(menuItemActionStr(SalesFormLetter_PackingSlipCancel), MenuItemType::Action).run(args);
     }


To Reverse shipment:

 
 WHSShipmentTable                shipmentTable;
 WHSLoadLine                     loadlines, loadlines2;

     
         shipmentTable = WHSShipmentTable::find(ShipmentID);
    
      select loadlines 
         where loadlines.ShipmentId == shipmentTable.ShipmentId
         && loadlines.InventTransType == InventTransType::Sales;

     WHSReverseShipConfirm reverseShipConfirm = WHSReverseShipConfirm::newFromLoadTable(loadlines.whsLoadTable());

     reverseShipConfirm.reverseShipConfirm();
 

To reopen containers:

 WHSContainerTable               containerTable;
 WHSCloseContainerProfile        closeContainerProfile;
 WHSShipmentTable                shipmentTable;
      containerTable = WHSContainerTable::findByContainerId(ContainerId);
     closeContainerProfile = WHSCloseContainerProfile::find(containerTable.CloseContainerProfileId);
     shipmentTable = WHSShipmentTable::find(containerTable.ShipmentId);
     WHSContainerTable::reOpenContainer(
     shipmentTable.ShipmentId,
     containerTable.ContainerId);
 


Comments

Popular posts from this blog

Cannot select a record for update when the transaction is not started on the user connection attached. You need to begin transaction on the user connection first. in d365F&O

Multi select lookup in UI Builder class in D365F&O through x++ code.

Records to include in SSRS Report With UI Builder class