Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 2.23 KB

PX1043.md

File metadata and controls

60 lines (48 loc) · 2.23 KB

PX1043

This document describes the PX1043 diagnostic.

Summary

Code Short Description Type Code Fix
PX1043 Changes cannot be saved to the database from event handlers. Error Unavailable

Diagnostic Description

In RowPersisting event handlers, only the methods of the PXCache.Persist family (PersistInserted, PersistUpdated, and PersistDeleted) can be used to save changes to the database. In RowPersisted event handlers, changes can be saved to the database only when the database transaction is open, as shown in the following code.

protected virtual void _(Events.RowPersisted<SOOrder> e)
{
    if (e.TranStatus == PXTranStatus.Open)
    {
        // You can save changes to the database here.
    }
}

Changes cannot be saved to the database from other event handlers.

To fix the issue, you remove the code that saves the changes to the database from the event handler and rework the related business logic.

This diagnostic is displayed as a warning for the RowPersisted event handlers if no check is performed for the transaction status and if the Enable additional diagnostics for ISV Solution Certification option (in Tools > Options > Acuminator > Code Analysis) is set to False.

Example of Incorrect Code

public class DocItemMaint : PXGraph<DocItemMaint>
{
    ...
    protected virtual void _(Events.RowDeleted<DocItem> e)
    {
        DocItem item = e.Row;
        if (item == null) return;

        var deleted = new DocItemDel();
        deleted.InventoryID = item.InventoryID;
        deleted.BAccountID = item.BAccountID;
        deleted = delitem.Insert(deleted);
        try
        {
            Actions.PressSave(); // The PX1043 error is displayed for this line.
        }
        catch (Exception ex)
        {
            delitem.Cache.Clear();
        }
    }
    ...
}

Related Articles