Solved

Field Updated Event Handler Not Executing

  • 6 July 2022
  • 1 reply
  • 551 views

Userlevel 3
Badge +1

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);
}
}
}

}

 

icon

Best answer by Leonardo Justiniano 6 July 2022, 17:12

View original

1 reply

Userlevel 6
Badge +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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved