1
votes

In my acumatica application, I created a custom page where the user needs to insert data in the grid section. In order to validate the provided data, I implemented the RowInserting and RowUpdating Events.

The problem is that in the rowinserting event I first throw an error using the following code:

cache.RaiseExceptionHandling<DZField.size>(fieldLine, fieldLine.Size,
    new PXSetPropertyException(string.Format(ValidationMessages.FIELD_NOT_VALID_FORMAT, 
        "Size"), PXErrorLevel.RowError));

Then I set the e.Cancel property to true. But when the user changes the incorrect value and re-triggers the event, the row will have missing values which were not manipulated in the event.

I also tried to not set the e.Cancel property and instead throw a PXException, but even in this case other values in the row were reset.

1

1 Answers

2
votes

In your RowInserting event, you are not throwing an error, you are raising it.

From documentation, the RowInserting event handler is used to:

  1. Evaluate the data record that is being inserted.
  2. Cancel the insert operation by throwing an exception.
  3. Assign the default values to the fields of the data record that is being inserted.

If you use the throw syntax in a row inserting event, a popup window will appear with your error message and the record will not be visible in the grid. You shouldn't use e.Cancel for validations in RowInserting.

Example of cancelling insertion:

protected virtual void DACName_RowInserting(PXCache sender, 
                                            PXRowInsertingEventArgs e)
{
    throw new PXException(ErrorMessages.FieldIsEmpty, 
                          typeof(PaymentMethodAccount.paymentMethodID).Name);
}

Source: RowInserting Event

Regarding row updating, using e.Cancel for validations will cancel updating of all fields which are marked as dirty for that row. Sometimes that's what you want but based on your question I think that's something you want to avoid.

When validating individual fields you can use the field updating event which will not affect other fields or raise field exceptions. Throwing an error in a row event or setting e.Cancel in a row event will affect the whole row.