Skip to content

Latest commit

 

History

History
43 lines (34 loc) · 1.65 KB

PX1056.md

File metadata and controls

43 lines (34 loc) · 1.65 KB

PX1056

This document describes the PX1056 diagnostic.

Summary

Code Short Description Type Code Fix
PX1056 A PXGraph instance cannot be initialized inside the IsActive or IsActiveForGraph<TGraph> method. Error Unavailable

Diagnostic Description

You cannot create a graph instance in the IsActive method of a graph or DAC extension or in the IsActiveForGraph<TGraph> method of a graph extension because this creation can lead to a deadlock. Instead, to access a graph member, you can use database slots. For details, see the Restrictions in the IsActive Method section of the To Enable a Graph Extension Conditionally (IsActive) article.

Example of Incorrect Code

public static bool IsActive()
{
	var invoiceEntry = PXGraph.CreateInstance<SOInvoiceEntry>();
	return (bool)invoiceEntry.sosetup.Current.InspectionEnabled;
}

Example of Correct Code

private class SOSetupInspection : IPrefetchable
{
    public static bool InspectionEnabled =>
        PXDatabase.GetSlot<SOSetupInspection>("SOSetupInspection", typeof(SOSetup))._inspectionEnabled;
    private bool _inspectionEnabled;
    void IPrefetchable.Prefetch()
    {
        using (PXDataRecord soSetup =
            PXDatabase.SelectSingle<SOSetup>(new PXDataField<SOSetup.inspectionEnabled>()))
            if (soSetup != null) _inspectionEnabled = (bool)soSetup.GetBoolean(0);
    }
}

public static bool IsActive() => SOSetupInspection.InspectionEnabled;