Skip to main content
Answer

How to update custom fields in the SOOrderEntry graph on SOLine when deleting an SOShipmentEntry record?

  • September 11, 2024
  • 4 replies
  • 151 views

Forum|alt.badge.img

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

Best answer by darylbowman

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)

4 replies

jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • September 11, 2024

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
                }
            }

        }
 


darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • September 11, 2024

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)


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • September 11, 2024

@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();
}

@darylbowman Thanks! I will also give this a try!


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • November 12, 2024

Hi @AJohnson were you able to find a solution? Thank you!