I'm getting errors when trying to persist SO lines in Acumatica customization code. I created a new simple PXGraph class that defines a basic SOLine view for caching and persistence. It's simply:
public PXSelect<SOLine> OrderLines;
In custom code, it creates some SO lines in my view cache above, by doing a cache insert:
SOLine newOrderLineItem = lineGraph.OrderLines.Cache.Insert();
then using the resulting line to set its values before persistence. After adding these lines, I try to persist them. I've tried both:
lineGraph.OrderLines.Cache.Persist(PXDBOperation.Insert);
and:
lineGraph.Actions.PressSave();
and both give errors. The former says "'OrderDate' cannot be empty.". However, before the Persist is executed, all lines have an OrderDate value. The StackTrace shows that it's being thrown within the RowPersisting event. So sometime between the Persist() call and the default RowPersisting event (which I haven't defined), a line's OrderDate has been set to null, but I have no idea where. The latter says "'Cross-Reference' record raised at least one error", and "'Vendor/Customer' cannot be empty." However, the line's CustomerID and VendorID are not empty, and both are valid.
What can I do to either resolve these errors or persist the lines differently that actually works?
v17.209.0028
Persist() call stack:
at PX.Data.PXDBDefaultAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)
at PX.Data.PXCache`1.PersistInserted(Object row)
at PX.Data.PXCache`1.Persist(PXDBOperation operation)
at Aktion.Acumatica.Customizations.EDI.EEdiDocInboundProcess.CreateOrderAndLineItems(EEdiStOrdHed doc, EEdiStOrdHed origDoc)
at Aktion.Acumatica.Customizations.EDI.EEdiDocInboundProcess.CreateSalesOrder(EEdiStOrdHed doc)
Update (3/16): So I just subclassed SOLine to my own class and overrode the OrderDate property setter to trap it being set to null. This worked, but I still don't know what's trying to null it out since the call stack just tells me that its external code. In any case, now the error is "'Operation' cannot be empty.". I guess I'll keep defaulting fields and overriding setters from errors until I run out of fields -- or patience.