Missing Parameters
In the development of the Quality Inspection tab in the POReceiptEntry screen, issues have been identified when attempting to dynamically populate records based on POReceiptLine entries. These issues prevent the system from accurately reflecting all the required quality parameters for each InventoryID.
Scenario
- Setup
- SetupPurchaseParameter contains predefined quality parameters linked to specific InventoryIDs.
- POReceiptLine contains the InventoryID of items being received.
- Requirements
- When a record is added to POReceiptLine, the system should check if the InventoryID requires a quality check (InventoryItemExt.UsrNeedQualityCheck = true).
- For such InventoryIDs, all associated parameters from SetupPurchaseParameter should be added as new records in the Quality Inspection tab.
- Observed Issue
- Case 1 - Adding a line with an InventoryID having two parameters in SetupPurchaseParameter results in only one record being added to the Quality Inspection tab.
Code
using System;
using System.Collections.Generic;
using System.Linq;
using PX.Data;
using PX.Objects.PO;
namespace PX.Objects.PO
{
public class POReceiptEntryExt : PXGraphExtension<POReceiptEntry>
{
// Data view for the Quality Inspection tab, which will show records filtered by the Receipt Number.
public PXSelect<POReceiptQualityInspection,
Where<POReceiptQualityInspection.receiptNbr, Equal<Current<POReceipt.receiptNbr>>>> QualityInspection;
// Data view to retrieve the setup parameters associated with the InventoryID.
public PXSelect<SetupPurchaseParameter,
Where<SetupPurchaseParameter.inventoryID, Equal<Current<POReceiptLine.inventoryID>>>> SetupParameters;
// RowInserted event triggered when a new line is added to the POReceiptLine.
protected virtual void _(Events.RowInserted<POReceiptLine> e)
{
// Check if the event row is null to avoid null reference errors.
if (e.Row == null) return;
// Retrieve the custom field 'UsrNeedQualityCheck' from the InventoryItem using its extension.
var inventoryItemExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(
(InventoryItem)PXSelectorAttribute.Select<POReceiptLine.inventoryID>(e.Cache, e.Row));
// If 'UsrNeedQualityCheck' is not true, no further action is needed for this line.
if (inventoryItemExt?.UsrNeedQualityCheck != true) return;
// Retrieve the current PO Receipt header record to link Quality Inspection records.
var receipt = Base.Document.Current;
if (receipt == null) return;
// Fetch all setup parameters for the given InventoryID from SetupPurchaseParameter.
var parameters = SetupParameters.Select()
.RowCast<SetupPurchaseParameter>()
.ToList();
// If no parameters are defined for the InventoryID, no Quality Inspection records are created.
if (parameters.Count == 0) return;
// Loop through each parameter retrieved for the InventoryID.
foreach (var parameter in parameters)
{
// Create a new Quality Inspection record for each parameter.
var inspection = new POReceiptQualityInspection
{
ReceiptType = receipt.ReceiptType, // Populate with the current Receipt Type.
ReceiptNbr = receipt.ReceiptNbr, // Populate with the current Receipt Number.
LineNbr = e.Row.LineNbr, // Link with the POReceiptLine's Line Number.
InventoryID = e.Row.InventoryID, // Link with the Inventory ID from the POReceiptLine.
ParameterID = parameter.ParameterID, // Assign the Parameter ID from SetupPurchaseParameter.
QualityPass = false // Default the Quality Pass field to false.
};
// Insert the new Quality Inspection record into the database.
QualityInspection.Insert(inspection);
}
}
}
}can anyone tell me what I am missing here? herewith I have attached the customization project.