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);
}
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
Post a Comment