Skip to main content

I am trying to get a newly added package to have the Shipment Number in the Customer Ref Nbr 1 field automatically.

 

To do this I added a fieldDefaulting event as follows:

 

    protected void SOPackageDetailEx_CustomRefNbr1_FieldDefaulting(PXCache cache,       PXFieldDefaultingEventArgs e)
{

var row = (SOPackageDetailEx)e.Row;

if (row == null) return;

e.NewValue = "SH#" + row.ShipmentNbr;

}

This works fine when I manually press to add a package but when I use auto pack it ends up with a field with: SH# <NEW> as I presume the row.ShipmentNbr is not populated at that point.  What should I use to get the shipment number before it is saved?

 

Thanks for any advice,

 

Phil

Hi @ppowell Can you please try the below code and verify.

 

 protected virtual void SOPackageDetailEx_RowPersisting(PXCache sender, PXRowPersistingEventArgs e, PXRowPersisting basecall)
{
basecall(sender, e);
SOPackageDetailEx row = (SOPackageDetailEx)e.Row;
if (row != null)
{
row.CustomRefNbr1 = "SH#" + row.ShipmentNbr;
Base.Packages.Cache.Update(Base.Packages.Current);
}
}

 


Hi @ppowell Above code might work but instead of using Current better use ROW like below.

 

protected virtual void SOPackageDetailEx_RowPersisting(PXCache sender, PXRowPersistingEventArgs e, PXRowPersisting basecall)
{
basecall(sender, e);
SOPackageDetailEx row = (SOPackageDetailEx)e.Row;
if (row != null)
{
row.CustomRefNbr1 = "SH#" + row.ShipmentNbr;
Base.Packages.Cache.Update(row); // I just changed to Current record to ROW.
}
}

 


I tried it but I get the following when I try to save on the Shipment screen with either of the above:

An unhandled exception has occurred in the function 'MoveNext'. Please see the trace log for more details.

 

Phil


Sorry, @ppowell  I have modified that code bit and please do verify with below and confirm.

 

I have verified from my end it is working as expected!!

 public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
protected virtual void SOPackageDetailEx_RowPersisting(PXCache sender, PXRowPersistingEventArgs e, PXRowPersisting basecall)
{

SOPackageDetailEx row = (SOPackageDetailEx)e.Row;
if (row != null)
{
row.CustomRefNbr1 = "SH#" + row.ShipmentNbr;
Base.Packages.Cache.Update(row); // I just changed to Current record to ROW.
}
basecall?.Invoke(sender, e);
}
}

 


@Naveen Boga This seems to be working great!

Thanks so much,

Phil


Most welcome, Phil and thanks a lot for sharing the update.


Reply