I have added a field called ‘Production Order No.’ which is meant to pull the production order number for the given line in Inventory Lot/ Serial History screen without having to click on reference number → go to manufacturing tab on issues screen → view production number.



I have added the code however it pulls incorrect details for some inventory SKUs.
namespace PX.Objects.IN
{
public class InventoryLotSerInq_Extension : PXGraphExtension<PX.Objects.IN.InventoryLotSerInq>
{
#region Event Handlers
protected virtual void INTranSplit_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
if (e.Row == null)
return;
var row = (InventoryLotSerInq.INTranSplit)e.Row;
if (string.IsNullOrEmpty(row.RefNbr) || string.IsNullOrEmpty(row.DocType))
return;
PXTrace.WriteInformation($"Processing INTranSplit_RowSelected for DocType: {row.DocType}, RefNbr: {row.RefNbr}");
try
{
// Get the INRegister for this transaction
INRegister inRegister = PXSelect<INRegister,
Where<INRegister.docType, Equal<Required<INRegister.docType>>,
And<INRegister.refNbr, Equal<Required<INRegister.refNbr>>>>>
.Select(Base, row.DocType, row.RefNbr)
.RowCast<INRegister>()
.FirstOrDefault();
if (inRegister == null)
{
PXTrace.WriteWarning($"No INRegister found for DocType: {row.DocType}, RefNbr: {row.RefNbr}");
return;
}
// Get the AMBatNbr from the INRegister extension
INRegisterExt inRegisterExt = PXCache<INRegister>.GetExtension<INRegisterExt>(inRegister);
if (inRegisterExt == null)
{
PXTrace.WriteWarning("INRegisterExt is null");
return;
}
string amBatNbr = inRegisterExt.AMBatNbr;
PXTrace.WriteInformation($"Found INRegister with AMBatNbr: {amBatNbr}");
if (string.IsNullOrEmpty(amBatNbr))
return;
// Find the AMMTran record using AMBatNbr
AMMTran amMTran = PXSelect<AMMTran,
Where<AMMTran.batNbr, Equal<Required<AMMTran.batNbr>>>>
.Select(Base, amBatNbr)
.RowCast<AMMTran>()
.FirstOrDefault();
if (amMTran == null)
{
PXTrace.WriteWarning($"No AMMTran found for AMBatNbr: {amBatNbr}");
return;
}
// Get the Production Order ID and set it to our extension field
string prodOrdID = amMTran.ProdOrdID;
PXTrace.WriteInformation($"Found Production Order ID: {prodOrdID}");
if (!string.IsNullOrEmpty(prodOrdID))
{
INTranSplitExt rowExt = sender.GetExtension<INTranSplitExt>(row);
if (rowExt != null)
{
rowExt.UsrMAINProdOrdID = prodOrdID;
PXTrace.WriteInformation($"Successfully set UsrMAINProdOrdID to {prodOrdID}");
}
else
{
PXTrace.WriteWarning("INTranSplitExt is null");
}
}
}
catch (Exception ex)
{
PXTrace.WriteError($"Error in INTranSplit_RowSelected: {ex.Message}\n{ex.StackTrace}");
}
}Please let me know if I have applied the correct filtering to get the production order number as mentioned in the steps above.
Thank you!
