Skip to main content

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! 

 

 

Try moving the warning to RowSelected event and replace PXSetPropertyException with SetWarning method:
protected virtual void _(Events.RowSelected<GRGrantsCustomers> e)
{
    PXUIFieldAttribute.SetWarning<GRGrantsCustomers.allocatedAmount>(e.Cache, e.Row, Messages.AllocatedTooMuch);
}


Hughes Beausejour, AWESOME!  Thank you for the quick assistance!

That worked perfectly.  I left this in the FieldVerifying event handler so I could change the amount of the field before the row was updated, but your code did the trick in my event.  I was trying to use the same methodology as in the T190 course but this is a much simpler statement too.  

I’m a lone ranger (just me here) and I wouldn’t know what to do if it wasn’t for people like you and Naveen in this forum.  You guys are life savers.


Reply