Hello Community,
I am working on the code below to generate a Shipment transfer and actually had a few issues. Anything look odd below that I can improve to get past these 2 issues? Note that some of the variables used are generated outside this block of code. The error generates on the “shipment.save.press()” according to my traces. Although I create the same transfer shipment the same way through the front end.
- Receiving error “CS Error: The document cannot be saved because the Shipping Address (Shipment Address) field in the database record that corresponds to this document is corrupted. Please try to save the document again. In case the issue remains, contact your Acumatica support provider for the assistance.” When saving in a custom processing screen.
- Cannot seem to get multiple transfer SOs added to the transfer shipment through the code.
trShipment = new SOShipment()
{
ShipmentType = "T",
SiteID = 862,
DestinationSiteID = 900
};
trShipment = shipment.Document.Insert(trShipment);
PXTrace.WriteInformation("1: ");
try
{
using (var ts = new PXTransactionScope())
{
foreach (SOLine s in orders)
{
SOLineExt sExt = PXCache<SOLine>.GetExtension<SOLineExt>(s);
PXTrace.WriteInformation("2: Searching for " + sExt.UsrSOTransferNbr + " to add to shipment.");
//if (!shipNbr.IsNullOrEmpty())
// shipment.Document.Current = shipment.Document.Search<SOShipment.shipmentNbr>(shipNbr, "T");
shipment.soshipmentplan.Cache.Clear();
shipment.addsofilter.Cache.Clear();
shipment.addsofilter.Current.OrderType = SOOrderTypeConstants.TransferOrder;
shipment.addsofilter.Current.OrderNbr = sExt.UsrSOTransferNbr;
shipment.addsofilter.Current.AddAllLines = true;
PXTrace.WriteInformation("2.1: Searching for " + sExt.UsrSOTransferNbr + " to add to shipment.");
shipment.addsofilter.Update(shipment.addsofilter.Current);
PXTrace.WriteInformation("2.2: Searching for " + sExt.UsrSOTransferNbr + " to add to shipment.");
shipment.soshipmentplan.Current = shipment.soshipmentplan.Search<SOShipmentPlan.orderNbr>(sExt.UsrSOTransferNbr, SOOrderTypeConstants.TransferOrder);
PXTrace.WriteInformation("2.3: Searching for " + sExt.UsrSOTransferNbr + " to add to shipment.");
foreach (SOShipmentPlan planLine in shipment.soshipmentplan.Select())
{
PXTrace.WriteInformation("3: Adding SO Lines from " + planLine.OrderNbr);
planLine.Selected = true;
shipment.soshipmentplan.Update(planLine);
}
PXTrace.WriteInformation("3.1:");
shipment.addSO.Press();
PXTrace.WriteInformation("3.2:");
shipment.Transactions.Update(shipment.Transactions.Current);
PXTrace.WriteInformation("3.3:");
//shipment.Actions.PressSave();
shipment.Document.Update(trShipment);
PXTrace.WriteInformation("3.4:");
shipment.Save.Press();
PXTrace.WriteInformation("3.5:");
shipNbr = shipment.Document.Current.ShipmentNbr;
PXTrace.WriteInformation("4: Saved shipment " + shipNbr);
orderEntry.Clear();
orderEntry.Document.Current = orderEntry.Document.Search<SOOrder.orderNbr>(s.OrderNbr, s.OrderType);
orderEntry.Transactions.Current = s;
sExt.UsrTransferShipment = shipNbr;
sExt.UsrRecertStatus = "SHIPMENT";
orderEntry.Transactions.Update(s);
orderEntry.Actions.PressSave();
//shipment.Clear();
}
ts.Complete();
PXProcessing<SOShipment>.SetInfo("Transfer shipment created successfully. Proceed to shipment to print paperwork and enter the shipping info.");
}
}
catch (Exception e)
{
PXProcessing<SOLine>.SetError(e);
}