Skip to main content

Hello, 

In various parts of the Acumatica source code I’m finding code similar to this. 

public void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
//some code
if (sender.RaiseExceptionHandling(_FieldName, e.Row, sender.GetValue(e.Row,_FieldName), new PXSetPropertyKeepPreviousException(Messages.errorMainWarehouse)))
{
throw new PXRowPersistingException(_FieldName, null, Messages.errorMainWarehouse2);
}
//more code
}

Does anyone know what this code is doing?

My theory was that 

“if (sender.RaiseExceptionHandling(_FieldName, e.Row, sender.GetValue(e.Row,_FieldName), new PXSetPropertyKeepPreviousException(Messages.errorMainWarehouse)))”

is checking to see if “RaiseExceptionHandling” has already been called against e.Row for _FieldName. I think it is specifically checking to see if Message.errorMainWarehouse was raised previously. If the RaiseExceptionHandling method returns True then we get to the PXRowPersistingException and an error is displayed on save. 

I think that “new PXSetPropertyKeepPreviousException” sounds like it should allow you to set a field value without clearing the current exception. 

The problem is that when I try to use this set up I cannot get the if(sender.RaiseExceptionHandling.. method to return true, so perhaps I’m misunderstanding why an “if” statement would be used with sender.RaiseExceptionHandling

 

Thanks

Steve

Hi @stephenward03 ,

  • The line 
sender.RaiseExceptionHandling

is used to raise an exception handling event for a specific field (_FieldName) on the row (e.Row).

  • This is typically done to perform validation or verification checks before persisting the row.
  • If the RaiseExceptionHandling method returns true, it indicates that an exception handling event has already been raised for the specified field on the row. This means that a previous validation or verification check has failed, and an exception has already been raised.
  • In the provided code, when the RaiseExceptionHandling method returns true, it means that the exception handling event for _FieldName has been raised previously, specifically with the error message Messages.errorMainWarehouse. In this case, the code throws a PXRowPersistingException with a different error message (Messages.errorMainWarehouse2), which will be displayed as an error during the save operation.
  • The new PXSetPropertyKeepPreviousException(Messages.errorMainWarehouse) part in the RaiseExceptionHandling call is used to set an exception message without clearing any previous exception that may have been raised.

Hope, it helps!

Regards,

Sweta


Thank you, Sweta, for the reply and explanation. It sounds like we have the same understanding of the code. May I ask if you have used a similar structure in your own projects?

The reason I ask is because I cannot get this code working in my project. In a RowUpdating event I call RaiseExceptionHandling to mark my field with the Messages.errorMainWarehouse error message. But in my RowPersisting event the If RaiseExceptionHandling() condition always returns false, so I never hit PXRowPersistingException

Thanks


Hi @stephenward03 

Sorry, I haven't used it till, but I believes PXSetPropertyKeepPreviousException is called only if a previous exception has occurred for the same field and another exception needs to be displayed. So, if you want the RaiseExceptionHandling() method to return true, first you have to throw an exception for the same field.

Regards,

Sweta


Hi @sweta68 

As explained in the previous message, I have used RaiseExceptionHandling in a RowUpdating event on the row/field before trying If (RaiseExceptionHandling… in the RowPersisting event. Sadly it returns a false in all my testing. 

I cannot find any documentation for PXSetPropertyKeepPreviousException. 

I’ll try so more testing. 

If anyone else as experience with this type of set up please get in touch.


Hi guys,

here screen shot of class PXCache with description, generic method is the same:

Method RaiseExceptionHandling returns bool value from OnExceptionHandling method and it is !Cancel

Cancel:

 

so, you always will get false, because method RaiseExceptionHandling doesn’t stop and break compiler and source code logic move on and do work line by line. Because if it, in your code we have line with throw

throw new PXRowPersistingException()

throw stops compiler and work of code.

Also, you can use fixes like e.Cancel = true;

Hope it will help you to combine and build needed logic.

 

 


Reply