Skip to main content
Answer

Issues while fetching records from another table

  • November 25, 2024
  • 1 reply
  • 45 views

Forum|alt.badge.img

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

  1. Setup
    • SetupPurchaseParameter contains predefined quality parameters linked to specific InventoryIDs.

AD_4nXfwValMcwglk7S1ppSZShiuTAtJFJdFueeyjR7Ib-HJuSYwWhD2FXS-DHJg5XkRCis1xCG9KsqbO-pmTjFSA6I6eTUs12dQFzHfobKWDUNtFIDiz_QUaL0DPrjS6W9Ix45WqUgOGQ?key=Q8J0tG8gw3iVKyqMP_qF1isp






 

  • POReceiptLine contains the InventoryID of items being received.

AD_4nXcx5USdEY_n8CY1mbbWg5WWB-fMPoJ8arA7NHgGRo6FhfkIyQIWSrAYXjW5mildPaSCIZ__TlNFgeNTX6pGS_nM_IKQrAUgK6htm5NQnpldViv3YYu4R-tuJJvS5_lSpJ-qWu2Qaw?key=Q8J0tG8gw3iVKyqMP_qF1isp

  1. 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.
  2. 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.

AD_4nXcH9geWL9lCUXguuuc5Sk8PoSv6JHzYho5vPtwXLbjMfIkxIW2h9HeNhKmXeqzXSnAOyR79beY1TsmzmMqScVZldRHSM3tOZU6-lxGdBPQCKgbCIy5FUQuQnJuGV_yjUgxsxLt1xA?key=Q8J0tG8gw3iVKyqMP_qF1isp

 

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.

Best answer by DipakNilkanth

Hi ​@RManathungage94,

You may need to modify the SetupParameters data view, as it is currently matching only the InventoryID It is likely that you also need to match additional fields, such as Parameter or another distinguishing field, to ensure the correct records are retrieved.

Debugging the code is essential here. Check what data is being retrieved by the SetupParameters view. By inspecting the data during runtime, you can identify if some records are being skipped or if the filtering logic is incorrect. This will help you pinpoint the root cause of the issue and make adjustments to ensure all required records are retrieved.
Hope, it helps!

1 reply

DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Pro III
  • Answer
  • November 25, 2024

Hi ​@RManathungage94,

You may need to modify the SetupParameters data view, as it is currently matching only the InventoryID It is likely that you also need to match additional fields, such as Parameter or another distinguishing field, to ensure the correct records are retrieved.

Debugging the code is essential here. Check what data is being retrieved by the SetupParameters view. By inspecting the data during runtime, you can identify if some records are being skipped or if the filtering logic is incorrect. This will help you pinpoint the root cause of the issue and make adjustments to ensure all required records are retrieved.
Hope, it helps!