Skip to main content

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).

Here is code:

    protected void SOShipment_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
{

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,

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

SOOrder objOrder = PXSelectJoin<SOOrder, InnerJoin<SOOrderShipment, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>,
And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>,
Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.Select(Base, Base.Document.Current?.ShipmentNbr);
if (objOrder != null)
{
SOOrderExt orderExt = objOrder.GetExtension<SOOrderExt>();
Base.Document.Current.GetExtension<SOShipmentExt>().UsrInvoiceNote = orderExt.UsrSONotes;
}
}
del();
}
}

 

 

 


Hi @Naveen Boga ,

I have tried your code but the order is still null

public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
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>();

SOOrder objOrder = PXSelectJoin<SOOrder, InnerJoin<SOOrderShipment, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>,
And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>,
Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.Select(Base, Base.Document.Current?.ShipmentNbr);
if (objOrder != null)
{
SOOrderExt orderExt = objOrder.GetExtension<SOOrderExt>();
Base.Document.Current.GetExtension<SOShipmentExt>().UsrSONotes = orderExt.UsrSONotes;
}
else{
Base.Document.Current.GetExtension<SOShipmentExt>().UsrSONotes = "Order is null";
}
}
del();
}
#endregion
}

The result:

Could you please have a look?

 

Thank you


Hi, @mrthanhkhoi   I don’t see any issues with the code.

Can you please debug and check whether Order Notes is coming or not?


Hi @Naveen Boga,

Actually, I don’t have source code of all library in the system so I modified event handling by using customization project editor

 

Sorry for asking a dump question, but is there any way for using visual studio to debugging when I don’t have all source code of library?

 

Thank you


@mrthanhkhoi  Okay! Once you published all the Project Editor code files will be added to the App-Runtime folder, you can debug in the Visual studio.

OR

if possible, can you please attach the customization project here, I can check from my end and let you know? 


Hi @Naveen Boga , please find the project find in attachments.

 


@mrthanhkhoi  Can you please share the version of the Acumatica?


Hi @Naveen Boga ,

Here is the version information

 


@mrthanhkhoi  Thanks for sharing the details. 

 

 

Please deploy the attached package and verify.


Hi @Naveen Boga ,

Thank you for your package. However, The result is not change.

Could you please share what you touch? I see the code is still the same


Hi @mrthanhkhoi  Here the updated code and I have verified and it is working fine.

public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
public delegate void PersistDelegate();
PXOverride]
public void Persist(Action del)
{
if (Base.Document.Current != null)
{
del();
SOOrder objOrder = PXSelectJoin<SOOrder, InnerJoin<SOOrderShipment, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>,
And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>,
Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.
Select(Base, Base.Document.Current?.ShipmentNbr);

PXTrace.WriteInformation("ShipmentNbr" + Base, Base.Document.Current?.ShipmentNbr);
if (objOrder != null)
{
SOOrderExt orderExt = objOrder.GetExtension<SOOrderExt>();
Base.Document.Current.GetExtension<SOShipmentExt>().UsrSONotes = orderExt.UsrSONotes;
}
else
{
Base.Document.Current.GetExtension<SOShipmentExt>().UsrSONotes = "Order is null";
}
Base.Document.Cache.Update(Base.Document.Current);
}
del();
}
#endregion
}

 


Hi @Naveen Boga,

it works for me.

Thank you very much for your help.

 

Have a nice day.

Khoi


Reply