I am not a good programmer so please feel free to tell me all the things I could do better… :-)
I am working in 2021R1.
I have a field that I am validating to make sure that it does not exceed a total amount on the header record.
My screen is functioning properly, but I should be getting a warning indicator, not an error.
My RaiseExceptionHandling is set at the Warning level BUT, I get a red X on the screen. What am I doing wrong here?
protected virtual void _(Events.FieldVerifying<GRGrantsCustomers, GRGrantsCustomers.allocatedAmount> e)
{
GRGrantsCustomers row = e.Row;
GRGrants grant = Grant.Current;
decimal? newValue = (decimal)e.Args.NewValue;
decimal? total = 0;
foreach (GRGrantsCustomers item in Customers.Select())
{
total += item.AllocatedAmount;
}
if (total - row.AllocatedAmount + newValue > grant.GrantAmount)
{
decimal balanceBeforeThisLine = grant.GrantAmount - total + row.AllocatedAmount ?? 0;
string balanceAvailable = balanceBeforeThisLine.ToString("0.##");
e.Cache.RaiseExceptionHandling<GRGrantsCustomers.allocatedAmount>(row,
balanceBeforeThisLine,
new PXSetPropertyException(Messages.AllocatedTooMuch, balanceAvailable, PXErrorLevel.Warning));
e.NewValue = balanceBeforeThisLine;
}
}
This is what the screen looks like when I enter 600 in the second line. It correctly sets it to 500, but it I want a yellow warning!