Skip to content

Latest commit

 

History

History
76 lines (59 loc) · 5.04 KB

File metadata and controls

76 lines (59 loc) · 5.04 KB

PX1073

This document describes the PX1073 diagnostic.

Summary

Code Short Description Type Code Fix
PX1073 Exceptions cannot be thrown in the RowPersisted and FieldUpdating event handlers. Error Unavailable

Diagnostic Description

No exceptions of any type can be thrown in the RowPersisted and FieldUpdating event handlers.

RowPersisted

The RowPersisted event handlers can be used for the following purposes:

  • Retrieval of the data from the database
  • Restoration of the values of the DAC fields if the status of the transaction scope is Aborted

An exception thrown in a RowPersisted event handler prevents the saving of the data to the database but does not roll back changes in PXCache instances, which leads to data inconsistency.

To prevent the error from occurring, you should remove the code that throws the exception and rework the related business logic. If you need to throw the exception to prevent saving of the record, you should use the RowPersisting event handler instead.

This diagnostic is displayed as a warning if the Enable additional diagnostics for ISV Solution Certification option (in Tools > Options > Acuminator > Code Analysis) is set to False.

The diagnostic does not show an error for the exception thrown in the RowPersisted event handler of a graph if at least one of the following conditions is met:

  • The graph declaring the RowPersisted event handler is a processing graph. For processing graphs all exception types are allowed.
  • The graph declaring the RowPersisted event handler is a non-processing graph and the type of the exception is among one of the following exception types or is derived from them:
    • PX.Data.PXRowPersistedException
    • PX.Data.PXLockViolationException
    • .NET exceptions from the System namespace: NotImplementedException, NotSupportedException, ArgumentException (including its descendants ArgumentNullException and ArgumentOutOfRangeException)

FieldUpdating

The FieldUpdating event handler can be used to transform the external representation of a value obtained from the UI or Web API into an internal representation stored in a DAC field. The handler is used in the following cases:

  • The external presentation of a DAC field (the value displayed in the UI) differs from the value stored in the DAC.
  • The storage of values is spread across multiple DAC fields (database columns).

A field updating event is usually raised for external updates of a DAC field value, for example, updates from the UI and Web API. This means that this event is not raised for some scenarios in which other Acumatica field events are fired. Scenarios that do not fire the field updating event include the following:

  • Calls from the application code to the PXCache.Update(object row) method
  • Calls from the application code to the PXCache.Delete(object row) method

Exceptions that are thrown in a field updating event handler are usually related to the validation logic declared in the event handler. Placing validation logic into a field updating event handler is risky because the validation will not be performed in all possible scenarios. Skipping the validation may leave the modified DAC field in an inconsistent state. You should move your logic to the FieldVerifying event handler which is a proper the proper place for validation of DAC field values.

The PX1073 diagnostic does not report an exception thrown in the FieldUpdating event handler if the exception type belongs to one of the following types or is derived from them:

  • .NET exceptions from the System namespace: NotImplementedException, NotSupportedException, ArgumentException (including its descendants ArgumentNullException and ArgumentOutOfRangeException)

Example of Incorrect Code

protected virtual void SOOrderLine_RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
{
    if (e.TranStatus == PXTranStatus.Completed)
    {
        if (e.Operation == PXDBOperation.Delete)
        {
            SOOrderLine row = (SOOrderLine)e.Row;
            SOOrderLine insertedLine = PXSelect<SOOrder,
                Where<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>
                .Select(this, row.orderNbr);
            if (insertedLine != null)
            {
                throw new PXException("Cannot delete"); //The PX1073 error is displayed for this line.
            }
        }
    }
}

Related Articles