Solved

Getting a red X not a yellow exclamation for a warning

  • 26 April 2021
  • 2 replies
  • 608 views

Userlevel 6
Badge +3

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! 

 

 

icon

Best answer by Hughes Beausejour 26 April 2021, 19:27

View original

2 replies

Userlevel 6
Badge +3

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.

Userlevel 5
Badge +2

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

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