How to retrieve SalesOrder in event RowInserted of Shipment
Hi,
I am implementing event handler RowInserted for Shipment with the goal: copy value a custom field from Sale Order and set it to the field on Shipment (also custom field).
var row = (SOShipment)e.Row; var query = new SelectFrom<SOOrder>.InnerJoin<SOOrderShipment>.On<SOOrder.orderNbr.IsEqual<SOOrderShipment.orderNbr> .And<SOOrder.orderType.IsEqual<SOOrderShipment.orderType>>> .Where<Use<SOOrderShipment.shipmentNbr>.AsString.IsEqual<@P.AsString>> .View(Base);
SOOrder order = query.Select(row.ShipmentNbr).TopFirst; if(order!=null){ var orderExt=order.GetExtension<SOOrderExt>(); row.GetExtension<SOShipmentExt>().UsrInvoiceNote=orderExt.UsrSONotes; }else{ row.GetExtension<SOShipmentExt>().UsrSONotes="SalesOrder is null"; } Base.Cachesstypeof(SOShipment)].Update(row); }
However, I always get the value of field on Shipment is “SalesOrder is null”.
I also tried with to take SalesOrder from the subgrid by using:
var order=Base.OrderList.Select().FirstOrDefault();
Does anyone have idea?
Thank you,
Page 1 / 1
Hi @mrthanhkhoi You can try with the below. While creating the shipment, Sales Order notes will be copied to the Shipment.
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry> { public delegate void PersistDelegate(); PXOverride] public void Persist(Action del) { if (Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted) { SOOrderEntry orderGraph = PXGraph.CreateInstance<SOOrderEntry>();