Reputation: 163
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.
Upvotes: 0
Views: 1519
Reputation: 5613
You should be looking at the PXFieldVerifyingEventArgs NewValue (e.NewValue
) to see what the new entered value is.
Example: (decimal?)e.NewValue % 50 == 0
When you use the row OrderQty you are looking at the value before the user entered the new value. To get the new value the user entered you need to look at NewValue for any field verifying event.
The SOOrderEntry
graph has an example of its use on OrderQty:
protected virtual void SOLine_OrderQty_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
{
if ((decimal?)e.NewValue < ((SOLine)e.Row).ClosedQty && ((SOLine)e.Row).RequireShipping == true && (((SOLine)e.Row).LineType == "GI" || ((SOLine)e.Row).LineType == "GN"))
{
throw new PXSetPropertyException(CS.Messages.Entry_GE, sender.GetStateExt<SOLine.closedQty>(e.Row));
}
}
Because of the thrown exception the warning will display but also cancel the entered value entered by the user. Because you are asking for a warning I assume you want to allow the user to enter in a non 50 lot qty value (and keep the entered value).
This example will surface the warning without cancelling the user entered value:
protected void SOLine_OrderQty_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying del)
{
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));
}
if (del != null)
{
del(cache, e);
}
}
Upvotes: 1