I have added some code to the SOShipmentEntry to automatically put the unpaid balance into the COD field when adding a new Package if the payment method ID is COD.
Each time a new package is added I need this amount to be split across the total number of packages. Likewise if one is removed it should update all to match.
I have code that will produce a list of the lines and am outputting to the Trace so I can see it’s getting the records correctly. This is in SOPackageDetailEx_COD_FieldDefaulting:
protected void SOPackageDetailEx_COD_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOPackageDetailEx)e.Row;
if (row == null) return;
SOShipLine item = Base.Transactions.Select().FirstOrDefault();
// Find how many packages have been added.
// First get all the package records from PackageDetailEx matching this ShipmentNbr
List<SOPackageDetailEx> lines1 = PXSelect<SOPackageDetailEx, Where<SOPackageDetailEx.shipmentNbr, Equal<Required<SOPackageDetailEx.shipmentNbr>>>>.Select(Base, item.ShipmentNbr).FirstTableItems.ToList();
var pkgCount = lines.Count + 1; // because we added a new package
var pkgCOD = unpaidBalance / Convert.ToDecimal(pkgCount);
foreach(SOPackageDetailEx pkgItem in lines)
{
PXTrace.WriteInformation("Package: " + pkgItem.LineNbr + " - " + pkgItem.COD + " - newCOD: " + pkgCOD);
}
e.NewValue = pkgCOD;
}
I’m not sure how to go about updating the previous package lines. I just need to loop through all lines setting the COD field value to pkgCOD and saving it before setting the NewValue.
Thanks for any help and sorry if this is totally the wrong way to go about this. I found other code that seemed to do what I wanted and modified it for this purpose.
Phil
Best answer by Naveen Boga
View original