Skip to main content
Question

Copied split custom field duplicates first line

  • May 20, 2025
  • 0 replies
  • 55 views

Forum|alt.badge.img

I setup some code for copying both row level and split custom fields from a Purchase Receipt to a Receipt. More about that linked here: 

This code currently results in a duplication of the first split line’s custom field value. The correct result would show (in the Receipt’s Line Details) “1” in the first row and “2” in the second row for the Vendor Lot/Serial Nbr.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Data.BQL.Fluent;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.GL;
using PX.Objects;
using PX.Objects.IN;
using PX.Objects.PO;

namespace PX.Objects
{
public class INReceiptEntry_Extension : PXGraphExtension<PX.Objects.IN.INReceiptEntry>
{
#region Event Handlers
protected void INTran_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
{
//the table to place Purchase Receipt values into, and the usual null check
INTran inTran = (INTran)e.Row;
if (inTran?.POReceiptNbr == null || inTran.POReceiptLineNbr == null) return;

//select from POReceiptLine where POReceiptLine.receiptNbr equals POReceiptLine.receiptNbr (required) and where POReceiptLine.lineNbr equals POReceiptLine.lineNbr (required). Insert selection into variable.
POReceiptLine prLine = PXSelect<POReceiptLine,
Where<POReceiptLine.receiptNbr, Equal<Required<POReceiptLine.receiptNbr>>,
And<POReceiptLine.lineNbr, Equal<Required<POReceiptLine.lineNbr>>>>>.
Select(Base, inTran.POReceiptNbr, inTran.POReceiptLineNbr);

if (prLine != null)
{
var inTranExt = cache.GetExtension<INTranExt>(inTran);
var prLineExt = PXCache<POReceiptLine>.GetExtension<POReceiptLineExt>(prLine);

inTranExt.UsrVendorLotSerialNbr = prLineExt.UsrPR_VendorLotSerialNbr;//copy standard row value
}
}

protected void INTranSplit_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
{
INTranSplit inTranSplit = (INTranSplit)e.Row;
if (inTranSplit?.RefNbr == null ) return;

//fetch the INTranSplit data from the related INTran
INTran inTran = PXSelect<INTran,
Where<INTran.docType, Equal<Required<INTran.docType>>,
And<INTran.refNbr, Equal<Required<INTran.refNbr>>,
And<INTran.lineNbr, Equal<Required<INTran.lineNbr>>>>>>
.Select(Base, inTranSplit.DocType, inTranSplit.RefNbr, inTranSplit.LineNbr);

if (inTran?.POReceiptNbr == null || inTran.POReceiptLineNbr == null) return;

//match the new Receipt data with data from POReceiptLine
POReceiptLine prLine = PXSelect<POReceiptLine,
Where<POReceiptLine.receiptNbr, Equal<Required<POReceiptLine.receiptNbr>>,
And<POReceiptLine.lineNbr, Equal<Required<POReceiptLine.lineNbr>>>>>
.Select(Base, inTran.POReceiptNbr, inTran.POReceiptLineNbr);

if (prLine == null) return;

//attempt to find matching POReceiptLineSplit
POReceiptLineSplit prLineSplit = PXSelect<POReceiptLineSplit,
Where<POReceiptLineSplit.receiptNbr, Equal<Required<POReceiptLineSplit.receiptNbr>>,
And<POReceiptLineSplit.lineNbr, Equal<Required<POReceiptLineSplit.lineNbr>>>>>
.Select(Base, prLine.ReceiptNbr, prLine.LineNbr);

if (prLineSplit != null)
{
var inTranSplitExt = PXCache<INTranSplit>.GetExtension<INTranSplitExt>(inTranSplit);
var prLineSplitExt = PXCache<POReceiptLineSplit>.GetExtension<POReceiptLineSplitExt>(prLineSplit);

inTranSplitExt.UsrSplitVendorLotSerialNbr = prLineSplitExt.UsrPR_SplitVendorLotSerialNbr;//copy split row value, this is currently copying the first split line multiple times
}
}
#endregion
}
}

Original Purchase Receipt:

 

Receipt released by the Purchase Receipt:

I figure this has something to do with the event handlers not iterating through properly. A foreach loop I tried resulted in two number “2”s being duplicated instead.