Solved

How to retrieve SalesOrder in event RowInserted of Shipment


Userlevel 3
Badge

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.Caches[typeof(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,

icon

Best answer by Naveen Boga 24 October 2022, 17:45

View original

12 replies

Userlevel 7
Badge +17

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

 

 

 

Userlevel 3
Badge

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

Userlevel 7
Badge +17

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

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

Userlevel 3
Badge

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

Userlevel 7
Badge +17

@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? 

Userlevel 3
Badge

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

 

Userlevel 7
Badge +17

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

Userlevel 3
Badge

Hi @Naveen Boga ,

Here is the version information

 

Userlevel 7
Badge +17

@mrthanhkhoi  Thanks for sharing the details. 

 

 

Please deploy the attached package and verify.

Userlevel 3
Badge

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

Userlevel 7
Badge +17

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
}

 

Userlevel 3
Badge

Hi @Naveen Boga,

it works for me.

Thank you very much for your help.

 

Have a nice day.

Khoi

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved