Skip to content

Latest commit

 

History

History
60 lines (51 loc) · 5.1 KB

File metadata and controls

60 lines (51 loc) · 5.1 KB

PX1075

This document describes the PX1075 diagnostic.

Summary

Code Short Description Type Code Fix
PX1075 PXCache.RaiseExceptionHandling cannot be invoked from the FieldDefaulting, FieldSelecting, FieldUpdating, RowSelecting, and RowPersisted event handlers. Warning (Non-ISV) / Error (ISV) Unavailable

Diagnostic Description

The PXCache.RaiseExceptionHandling method, which is used to prevent the saving of a record or to display an error or warning on the form, cannot be invoked on a PXCache instance for some event handlers.

The PXCache.RaiseExceptionHandling method usually is invoked in the following event handlers:

  • RowPersisting to prevent saving of a record.
  • RowSelected to display an error or a warning on the form.

To prevent the diagnostic from showing an error, you should remove the code that invokes PXCache.RaiseExceptionHandling and rework the related business logic.

When Enable additional diagnostics for ISV Solution Certification Acuminator option (in Tools > Options > Acuminator > Code Analysis) is set to True, the PX1073 diagnostic will be displayed as an error for the following event handlers:

  • FieldDefaulting: This event handler works with a record that has not yet been added to PXCache or a record whose field is changed in the code. Neither situation involves the display of errors or warning for a record.
  • FieldSelecting: This event handler is used to configure a UI control of a field. The invocation of PXCache.RaiseExceptionHandling in this event handler has no effect.
  • FieldUpdating: This event handler is used to transform external value representation from the UI or Web API into the internal value representation stored in a DAC field. The FieldUpdating event is not raised in some scenarios when Acumatica assumes that value is already in an internal state and does not require transformation. Therefore, the validation logic that calls PXCache.RaiseExceptionHandling won't be executed in all scenarios which can lead to an inconsistent state of the value in the DAC field. You should use FieldUpdating or other event handlers for validation logic.
  • RowSelecting: This event handler is called when the record is being read from the database. These records are not available in PXCache yet. Invocation of PXCache.RaiseExceptionHandling in this event handler has no effect.
  • RowPersisted: This event handler is called when the record has already been saved to the database. Therefore, it would not make sense to display any warnings for this record.

When Enable additional diagnostics for ISV Solution Certification Acuminator option (in Tools > Options > Acuminator > Code Analysis) is set to False, the PX1073 diagnostic will be displayed as a Warning for the following event handlers:

  • FieldSelecting: This event handler is used to configure a UI control of a field. The invocation of PXCache.RaiseExceptionHandling in this event handler has no effect.
  • FieldUpdating: This event handler is used to transform external value representation from the UI or Web API into the internal value representation stored in a DAC field. The FieldUpdating event is not raised in some scenarios when Acumatica assumes that value is already in an internal state and does not require transformation. Therefore, the validation logic that calls PXCache.RaiseExceptionHandling won't be executed in all scenarios which can lead to an inconsistent state of the value in the DAC field. Use FieldUpdating or other event handlers for validation logic.

Example of Incorrect Code

protected virtual void SOOrder_Status_FieldSelecting(PXCache sender,
PXRowSelectingEventArgs e)
{
    SOOrder row = (SOOrder)e.Row;
    if (row.Status != "New" )
    {
        sender.RaiseExceptionHandling<SOOrder.status>( //The PX1075 error is displayed for this line.
            row, null,
            new PXSetPropertyException(
                Messages.SpecialText,
                typeof(SOOrder.status).Name));
        e.Cancel = true;
    }
}

Related Articles