In ax D365F&O post packing slip from shipment through code x++.

 Hi viewers,

To post the packing slip for the sales order from the shipment, we first have to close the containers, confirm the shipment, and then post the packing slip.

these steps can be handled either through code or manually updated from the form by the user.

I am sharing the code to update accordingly.

To Close the container.

 public void closeContainer()
 {
     WHSContainerTable               containerTable;
     WHSCloseContainerProfile        closeContainerProfile;
     WHSShipmentTable                shipmentTable;

     
         containerTable = WHSContainerTable::findByContainerId(PackageDetailsTable.ContainerId);
         closeContainerProfile = WHSCloseContainerProfile::find(containerTable.CloseContainerProfileId);

         shipmentTable = WHSShipmentTable::find(containerTable.ShipmentId);

         WHSContainerTable::closeContainer(shipmentTable.ShipmentId,
                                             containerTable.ContainerId,
                                             PackageDetailsTable.Weight,
                                             closeContainerProfile.WeightUOM,
                                             closeContainerProfile.DefaultFinalShipLoc,
                                             true,
                                             PackageDetailsTable.TrackingNumber);
     


 }

To Confirm shipment: 

 WHSContainerTable               containerTable;
 WHSShipmentTable                shipmentTable;
 
     containerTable = WHSContainerTable::findByContainerId(PackageDetailsTable.ContainerId);
     shipmentTable = WHSShipmentTable::find(containerTable.ShipmentId);
     if(shipmentTable.ShipmentStatus == WHSShipmentStatus::Loaded)
     {
         whsshipconfirm::performActionOnBuffer(WHSShipConfirmAction::ConfirmShipment, shipmentTable);
     }
 


To post packingSlip:


 salesFormLetter = SalesFormLetter_PackingSlip::newPackingSlip();
 salesFormLetter.allowEmptyTable(salesFormLetter.initAllowEmptyTable(true));
 salesFormLetter.multiForm(true);
 salesFormLetter.getLast();
 SalesFormletter.parmShipmentId(shipmentTable.ShipmentId);
 SalesFormletter.parmWHSLoadId(shipmentTable.LoadId);
 SalesFormletter.update(shipmentTable.whsLoadTable(), today(), SalesUpdate::PickingList, AccountOrder::None, false, false);

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