I’m trying to programatically created Sales Shipments: given a despatch message from the third-party warehouse, I locate the sales order and then use CreateShipmentIssue to construct the shipment.
This works fine when I run the action as a user. But fails every time when running as a Process via the automation scheduler.
My code simplifies to:
orderGraph.Clear();
orderGraph.Document.Current = PXSelect<SOOrder,Where<SOOrder.orderNbr,Equal<Required<SOOrder.orderNbr>>>>.Select(orderGraph, orderNbr);
PXAdapter adapter = new PXAdapter(PXView.Dummy.For<SOOrder>(orderGraph)) { AllowRedirect = false, MassProcess = false };
var orders = orderGraph.CreateShipmentIssue(adapter, receivedItem.ShippedDate, siteID, DateTime.UtcNow);
The error is:
PX.Data.PXRowPersistingException: Error: 'CuryID' cannot be empty.
at PX.Data.PXDefaultAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
at PX.Data.PXCache.AttributeHandlersSquasher`1.<>c__DisplayClass2_0`1.<To>b__0(PXCache cache, TArgs args)
at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)
at PX.Data.PXCache`1.PersistInserted(Object row, Boolean bypassInterceptor)
at PX.Data.PXCache`1.Persist(PXDBOperation operation)
..
at Wrapper.PX.Objects.SO.Cst_SOOrderEntry.CreateShipment(PXAdapter adapter, Nullable`1 shipDate, Nullable`1 siteID, Nullable`1 endDate, String operation)
at PX.Objects.SO.SOOrderEntry.CreateShipmentIssue(PXAdapter adapter, Nullable`1 shipDate, Nullable`1 siteID, Nullable`1 endDate)
What might I have missed? (I know that when the process runs it’s as the admin user and the Branch won’t get set from the user default, but surely the Branch would be taken from the Sales Order?)