Skip to main content
Solved

Field Updated Event Handler Not Executing

  • July 6, 2022
  • 1 reply
  • 670 views

Forum|alt.badge.img+2

Hi, I have a requirement where some validations are to occur once the inventory ID field is updated in the Requisitions screen. The logic is based on values taken from custom fields in a custom form and synced with user defined field in Summary area of requisition form and line item’s inventory ID. The logic is attached but the warning and error messages are not executed. Please let me know how to solve this issue.

Custom Form Record 
Validated By Referencing these 2 Fields
 protected virtual void RQRequisitionLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
        {
            InvokeBaseHandler?.Invoke(cache, e);
            RQRequisitionLine rowLine = (RQRequisitionLine)e.Row;
            if (rowLine == null) return;

            // Get current Requisition
            RQRequisition row = Base.Document.Current;
            // Find my custom field from Extension
            var ext = PXCache<RQRequisition>.GetExtension<RQRequisitionExt>(row);
            DateTime currentDate = DateTime.Today;

            // Find record from VNPIProjectItem custom form view 
            foreach (VOPIProjectItem projectItemList in PXSelect<VOPIProjectItem>.Select(Base).FirstTableItems)
            {
                //loop through requisition line records
                foreach (RQRequisitionLine lines in PXSelect<RQRequisitionLine, Where<RQRequisitionLine.reqNbr, Equal<Required<RQRequisition.reqNbr>>>>
                .Select(Base, row.ReqNbr))
                {
                    if (ext.UsrprojectSelectorCustom == "NONPROJECT")
                    {                       
                        string warningMsg = "Non-Project ID Selected";
                        throw new PXSetPropertyException(warningMsg, PXErrorLevel.Warning);

                    }
                    if ((!ext.UsrprojectSelectorCustom.Equals("NONPROJECT")) && (!projectItemList.ProjectID.Contains(ext.UsrprojectSelectorCustom.Trim())
                  && lines.InventoryID != Convert.ToInt32(projectItemList.StockItemID.Trim())) &&
                  (currentDate >= projectItemList.StartDate && currentDate <= projectItemList.EndDate))
                    {
                        string errorMsg = "Project Item Budget does not Exist";
                        throw new PXSetPropertyException(errorMsg, PXErrorLevel.Error);
                    }
                    if (lines.OrderQty > projectItemList.BalanceQty)
                    {
                        string errorMsg = "Project Budget Quantity has been Exceeded";
                        throw new PXSetPropertyException(errorMsg, PXErrorLevel.Error);
                    }
                }
            }

        }

 

Best answer by Leonardo Justiniano

Hi @TharidhiP 

I see you are trying to validate the lines. Please do the query against the cache on the loop:

foreach (RQRequisitionLine lines in PXSelect<RQRequisitionLine, Where<RQRequisitionLine.reqNbr, Equal<Required<RQRequisition.reqNbr>>>>
                .Select(Base, row.ReqNbr))
{
   ...
}

by


foreach (var lineResult in Base.Lines.Select())
{
   RQRequisitionLine line = (RQRequisitionLine)lineResult;
   .....
}

Lines will not be inserted till you save the document.

Also I recommend to do this validation on RQRequisition Persisting event as it can be heavy while editing the grid.

 

View original
Did this topic help you find an answer to your question?

1 reply

Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

Hi @TharidhiP 

I see you are trying to validate the lines. Please do the query against the cache on the loop:

foreach (RQRequisitionLine lines in PXSelect<RQRequisitionLine, Where<RQRequisitionLine.reqNbr, Equal<Required<RQRequisition.reqNbr>>>>
                .Select(Base, row.ReqNbr))
{
   ...
}

by


foreach (var lineResult in Base.Lines.Select())
{
   RQRequisitionLine line = (RQRequisitionLine)lineResult;
   .....
}

Lines will not be inserted till you save the document.

Also I recommend to do this validation on RQRequisition Persisting event as it can be heavy while editing the grid.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings