Hello community. In the code below I am doing a few things, creating a sales order of the transfer type from shipments of the receipt type. I am saving the shipment number to the transfer order and the newly created sales order number to the shipment. It is doing exactly what I want minus saving the new SO # to the shipment record. I am doing this in an enclosed “using (var ts = new PXTransactionScope())” and was wondering if its possible I am not able to update multiple graph instances at once? Or is there another issue below that is not saving my SO # to the shipment record? I have the correct order number coming back into the code in my PXTrace. Any ideas? Thanks in advance!
public PXProcessing<SOShipment, Where<SOShipment.operation, Equal<SOOperation.receipt>, And<Where<SOShipmentExt.usrToTransfer, IsNull, Or<SOShipmentExt.usrToTransfer.IsEqual<False>>>>>> shipments;
public createTransfers()
{
shipments.SetProcessCaption("Process");
shipments.SetProcessAllCaption("Process All");
shipments.SetProcessDelegate(CreateTransferOrders);
}
public static void CreateTransferOrders(List<SOShipment> shipments)
{
if (shipments.Count <= 0)
return;
WriteInformation("Start Processing");
foreach (SOShipment s in shipments)
{
try
{
using (var ts = new PXTransactionScope())
{
WriteInformation("Transaction");
var orderEntry = PXGraph.CreateInstance<SOOrderEntry>();
var shipment = PXGraph.CreateInstance<SOShipmentEntry>();
shipment.Document.Current = shipment.Document.Search<SOShipment.shipmentNbr>(s.ShipmentNbr);
SOOrder order = new SOOrder();
SOLine sOLine = new SOLine();
order.OrderType = "TR";
order.DestinationSiteID = 900;
order.CustomerID = s.CustomerID;
SOOrderExt orderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(order);
orderExt.UsrFromShipment = true;
orderExt.UsrFromShipNbr = s.ShipmentNbr.ToString();
order = orderEntry.Document.Insert(order);
PXTrace.WriteInformation(s.ShipmentNbr);
PXTrace.WriteInformation("Line Item Population");
PXSelectBase<SOShipLine> cmd = new PXSelectReadonly<SOShipLine, Where<SOShipLine.shipmentNbr, Equal<SOShipment.shipmentNbr.FromCurrent>>>(shipment);
foreach (SOShipLine sl in cmd.Select())
{
PXTrace.WriteInformation(sl.InventoryID.ToString());
sOLine.InventoryID = sl.InventoryID;
sOLine.OrderQty = sl.Qty;
sOLine.SiteID = sl.SiteID;
sOLine.UnitPrice = sl.UnitPrice;
sOLine.UnitCost = sl.UnitCost;
//sOLine.CustomerID = sl.CustomerID;
sOLine.OrderType = "TR";
sOLine = orderEntry.Transactions.Insert(sOLine);
}
orderEntry.Transactions.Cache.Update(orderEntry);
orderEntry.Actions.PressSave();
PXSelectBase<SOOrder> cmdOrder = new PXSelectReadonly<SOOrder, Where<SOOrderExt.usrFromShipment, Equal<SOShipment.shipmentNbr.FromCurrent>>>(shipment);
SOShipmentExt shipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(shipment.Document.Current);
foreach (SOOrder or in cmdOrder.Select())
{
PXTrace.WriteInformation(or.OrderNbr);
shipmentExt.UsrToTransfer = true;
shipmentExt.UsrToTransferNbr = or.OrderNbr;
}
shipment.Document.Current = shipment.Document.Update(shipment.Document.Current);
shipment.Transactions.Cache.Update(shipment);
shipment.Actions.PressSave();
ts.Complete();
PXProcessing<SOShipment>.SetInfo(s.ShipmentNbr + " transfer created successfully.");
}
}
catch (Exception e)
{
PXProcessing<SOShipment>.SetError(shipments.IndexOf(s), e);
}
}
}