I am trying to set a warning on the OrderQty field when a certain UOM is selected. We have a UOM that is only in qty multiples of 50 so this must mean that the qty should be set to a multiple of 50. I would like a warning to display if the user entered let's say 40 then it would say this should be entered in a multiple of 50. My code compiles fine it just does not throw the warning when entering a value that should throw the exception.
SOOrder Entry Graph:
protected void SOLine_OrderQty_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
{
var row = (SOLine)e.Row;
if (row == null) return;
SOLine line = Base.Transactions.Current;
if (line.UOM != "CCP") return;
if (line.UOM == "CCP")
{
if (line.OrderQty % 50 == 0) return;
else
{
throw new PXSetPropertyException("Please enter a value in multiples of 50.", PXErrorLevel.Warning);
}
}
}
I have also tried:
protected void SOLine_OrderQty_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
{
var row = (SOLine)e.Row;
if (row == null) return;
if (row.UOM != "CCP") return;
if (row.UOM == "CCP")
{
if (row.OrderQty % 50 == 0) return;
else
{
throw new PXSetPropertyException("Please enter a value in multiples of 50.", PXErrorLevel.Warning);
}
}
}
CCP is the UOM that should only have Qty's in the multiples of 50 and no other UOM should throw a warning if it is not set.
Update 1: Updated the code to this:
protected void SOLine_OrderQty_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
{
var row = (SOLine)e.Row;
if (row == null) return;
if (row.UOM != "CCP") return;
if (row.UOM == "CCP")
{
if ((decimal?)e.NewValue % 50 == 0) return;
if ((decimal?) e.NewValue % 50 != 0)
{
cache.RaiseExceptionHandling<SOLine.orderQty>(e.Row, ((SOLine)e.Row).OrderQty,
new PXSetPropertyException("Please enter a value in multiples of 50.", PXErrorLevel.Warning));
}
}
}
I have changed to the e.NewValue state for the value entered. The warning message is still not thrown.
var row = (SOLine)e.Row;bevar row = e.Row as SOLine;? Andif (line.UOM == "CCP")is not needed. - George Chen