How to update custom fields in the SOOrderEntry graph on SOLine when deleting an SOShipmentEntry record?
Hello community, I am looking for some guidance on how to “reset” a few custom fields on a sales order if the related shipment entry is deleted. I was able to get these fields to update when creating a shipment. However, I am a little lost on how to get them to clear on a shipment deletion. For inserting them I wrote an override to “CreateShipment”. For the deletion, I tried to do a SOShipLine_RowDeleted, but cannot reference the SOOrderEntry due to the “PX1045: A PXGraph instance cannot be created within an event handler.” Any help is much appreciated!
Thanks,
Adam
Page 1 / 1
Hi @AJohnson
Could you please try with the below code sample?
PXOverride] public void Persist(Action del) { if (Base.Document.Cache.Deleted != null) { foreach (var item in Base.OrderList.Select()) // get the order details { //do the order update } }
}
The PXForeignReference DAC attribute can be used to enforce such a policy:
//placed on the child DAC (ReferenceBehavior is optional) /PXForeignReference(typeof(CompositeKey< Field<usrPDPOType>.IsRelatedTo<POOrder.orderType>, Field<usrPDPONbr>.IsRelatedTo<POOrder.orderNbr>>), ReferenceBehavior.SetNull)]
Placing this on your custom field(s) can declare a reference to another entity. If that entity is deleted, you can choose what will happen to the value stored in your custom field(s) (ie: SetNull)
(In this code example, the relationship is to a POOrder)
@jinin Thanks! I have a few questions as I have been trying to build what I need done using the code you sent over. For some reason, there doesnt appear to be any data in Base.OrderList.Select() when I am testing with my traces. Guessing I am missing something below. Any ideas?
PXOverride] public void Persist(Action del) { if (Base.Document.Cache.Deleted != null) { PXTrace.WriteInformation("DELSHIP 1.0: " + Base.OrderList.Select().FirstOrDefault()); foreach (var item in Base.OrderList.Select()) // get the order details { PXTrace.WriteInformation("DELSHIP 1.1: " + item); var orderEntry = PXGraph.CreateInstance<SOOrderEntry>(); orderEntry.Document.Current = orderEntry.Document.Search<SOOrder.orderNbr>(item); } } del(); }