Hello Community! I had a question on how to create a shipment with multiple SOs attached through code in a processing screen. My main processing table is SOLine and the code I am attempting is below. This is for a transfer shipment which is why I have no customer ID. The shipment gets created without issue but no line items populate. My trace shows the loop through SOShipmentPlan finding the SOs I am selecting to add but I seem to be missing something.
public static string TransferShipment(SOOrderEntry orderEntry, SOShipmentEntry shipment, List<SOLine> lines, string sOShipmentType, string operation)
{
PXTrace.WriteInformation("1: Building shipment");
string shipNo = String.Empty;
List<SOShipmentPlan> plan = new List<SOShipmentPlan>();
PXTrace.WriteInformation("0: ");
SOShipment trShipment = new SOShipment()
{
ShipmentType = sOShipmentType
};
trShipment = shipment.Document.Insert(trShipment);
trShipment.SiteID = 862;
trShipment.DestinationSiteID = 900;
trShipment.Operation = operation;
try
{
shipment.Document.Update(trShipment);
//shipment.Actions.PressSave();
}
catch (Exception e)
{
PXFilteredProcessing<SOLine, RecertificationFilter>.SetError(e);
}
shipNo = shipment.Document.Current.ShipmentNbr;
foreach (SOLine s in lines)
{
foreach (PXResult<SOShipmentPlan, SOLineSplit, PX.Objects.SO.SOOrderShipment, SOOrder> res in
PXSelectJoin<SOShipmentPlan,
InnerJoin<SOLineSplit,
On<SOLineSplit.planID, Equal<SOShipmentPlan.planID>>,
LeftJoin<PX.Objects.SO.SOOrderShipment,
On<PX.Objects.SO.SOOrderShipment.orderType, Equal<SOShipmentPlan.orderType>,
And<PX.Objects.SO.SOOrderShipment.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<PX.Objects.SO.SOOrderShipment.operation, Equal<SOLineSplit.operation>,
And<PX.Objects.SO.SOOrderShipment.siteID, Equal<SOShipmentPlan.siteID>,
And<PX.Objects.SO.SOOrderShipment.confirmed, Equal<boolFalse>,
And<PX.Objects.SO.SOOrderShipment.shipmentNbr, NotEqual<Current<SOShipment.shipmentNbr>>>>>>>>,
InnerJoin<SOOrder,
On<SOOrder.orderType, Equal<SOShipmentPlan.orderType>,
And<SOOrder.orderNbr, Equal<SOShipmentPlan.orderNbr>,
And<SOOrder.cancelled, Equal<boolFalse>,
And<SOOrder.completed, Equal<boolFalse>,
And<SOOrder.hold, Equal<False>,
And<SOOrder.creditHold, Equal<False>>>>>>>>>>,
Where<SOShipmentPlan.orderType, Equal<Required<SOShipmentPlan.orderType>>,
And<SOShipmentPlan.siteID, Equal<Current<SOShipment.siteID>>,
And<SOShipmentPlan.inventoryID, Equal<Required<SOLine.inventoryID>>,
And<SOShipmentPlan.orderNbr, Equal<Required<SOLine.orderNbr>>,
And<PX.Objects.SO.SOOrderShipment.shipmentNbr, IsNull,
And<SOLineSplit.operation, Equal<Required<SOLineSplit.operation>>
>>>>>>>
.Select(shipment, SOOrderTypeConstants.TransferOrder, s.InventoryID, sExt.UsrSOTransferNbr, operation))
{
PXTrace.WriteInformation("2 (1): Searching for " + sExt.UsrSOTransferNbr + " to add to shipment.");
var planLine = (SOShipmentPlan)res;
plan.Add(planLine);
}
}
foreach(SOShipmentPlan p in plan)
{
PXTrace.WriteInformation("3: Adding " + p.OrderNbr + " to shipment.");
p.Selected = true;
shipment.soshipmentplan.Update(p);
PXTrace.WriteInformation("3.1: Saving Shipment");
try
{
shipment.addSO.Press();
shipment.Transactions.Update(shipment.Transactions.Current);
}
catch (Exception e)
{
PXFilteredProcessing<SOLine, RecertificationFilter>.SetError(e);
}
}
shipment.Document.Update(shipment.Document.Current);
shipment.Actions.PressSave();
return shipNo;
}
I’ve gone through a few other iterations without much luck. Below is another version I did that successfully created multiple shipments for each individual sales order selected and one blank shipment for some reason. But I need them on one individual shipment.
public static string TransferShipment(SOOrderEntry orderEntry, SOShipmentEntry shipment, List<SOLine> lines, string sOShipmentType, string operation)
{
PXTrace.WriteInformation("1: Building shipment");
string shipNo = String.Empty;
List<SOShipmentPlan> plan = new List<SOShipmentPlan>();
PXTrace.WriteInformation("0: ");
SOShipment trShipment = new SOShipment()
{
ShipmentType = sOShipmentType
};
trShipment = shipment.Document.Insert(trShipment);
trShipment.SiteID = 862;
trShipment.DestinationSiteID = 900;
trShipment.Operation = operation;
try
{
shipment.Document.Update(trShipment);
//shipment.Actions.PressSave();
}
catch (Exception e)
{
PXFilteredProcessing<SOLine, RecertificationFilter>.SetError(e);
}
shipNo = shipment.Document.Current.ShipmentNbr;
foreach (SOLine s in lines)
{
SOLineExt sExt = PXCache<SOLine>.GetExtension<SOLineExt>(s);
//orderEntry.Document.Current = orderEntry.Document.Search<SOOrder.orderNbr>(s.OrderNbr, s.OrderType);
//orderEntry.Transactions.Current = s;
shipment.addsofilter.Cache.Clear();
//SOLineSplit serialLine = PXSelect<SOLineSplit,
// Where<SOLineSplit.orderNbr, Equal<Required<SOLine.orderNbr>>,
// And<SOLineSplit.orderType, Equal<Required<SOLine.orderType>>,
// And<SOLineSplit.inventoryID, Equal<Required<SOLine.inventoryID>>,
// And<SOLineSplit.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>>.Select(new PXGraph(), s.OrderNbr, s.OrderType, s.InventoryID, s.LineNbr);
if (operation.Equals(SOOperation.Issue) && sOShipmentType.Equals(SOShipmentType.Transfer))
{
PXTrace.WriteInformation("2 (1): Searching for " + sExt.UsrSOTransferNbr + " to add to shipment.");
//orderEntry.Document.Current = orderEntry.Document.Search<SOOrder.orderNbr>(sExt.UsrSOTransferNbr, SOOrderTypeConstants.TransferOrder);
shipment.addsofilter.Current.OrderType = SOOrderTypeConstants.TransferOrder;
shipment.addsofilter.Current.OrderNbr = sExt.UsrSOTransferNbr;
}
else
{
PXTrace.WriteInformation("2 (2): Searching for " + s.OrderNbr + " to add to shipment.");
shipment.addsofilter.Current.OrderType = s.OrderType;
shipment.addsofilter.Current.OrderType = s.OrderNbr;
}
shipment.addsofilter.Current.AddAllLines = true;
shipment.addsofilter.Update(shipment.addsofilter.Current);
foreach (SOShipmentPlan line in shipment.soshipmentplan.Select())
{
line.Selected = true;
shipment.soshipmentplan.Update(line);
}
PXTrace.WriteInformation("3.1: Saving Shipment");
try
{
shipment.addSO.Press();
}
catch (Exception e)
{
PXFilteredProcessing<SOLine, RecertificationFilter>.SetError(e);
}
}
try
{
trShipment = shipment.Document.Update(trShipment);
shipment.Actions.PressSave();
}
catch (Exception e)
{
PXFilteredProcessing<SOLine, RecertificationFilter>.SetError(e);
}
return shipment.Document.Current.ShipmentNbr;
}
I’ve found some articles online but most of them appear to be outdated and I didnt have much luck. Any ideas?
Thanks,
Adam