Loading ...

Streamlining Acumatica Development with Preprocessor Directives

As of version 24R1, Acumatica has introduced a notable enhancement. This change affects how developers declare Data Access Classes (DACs) and their inheritance from PX.Data.BQL interfaces .

This concerns a change where you now need to inherit from PXBqlTable, IBqlTable when declaring a DAC, for example:

public sealed class Table1 : PXBqlTable, IBqlTable

{

// your fields

}

However, managing multiple versions, such as 23R2 and 24R1, can become cumbersome. Preprocessor directives offer an elegant solution to address this challenge. Here’s an example:

#if _24R1

public sealed class Table1 : PXBqlTable, IBqlTable

#else

public sealed class Table1 : IBqlTable

#endif

{

[PXString(255, IsUnicode = true)]

[PXUIField(DisplayName = "Field")]

public string Field { get; set; }

public abstract class field : PX.Data.BQL.BqlString.Field<field> { }

}

How It Works

Define the Version:
Specify the version (e.g.,
_24R1) in your project settings. This ensures the relevant code block executes. If the version field is empty, the else block will apply.


Flexible Conditions:
You can create as many conditions as necessary to accommodate all your project versions, saving hours of repetitive work when upgrading or switching between versions.

Managing References with Folders

Instead of replacing DLLs each time you switch between versions, organize your references in folders like references/24R1 or references/23R2. Then, update your project file using a text editor to include an ItemGroup with conditions for selecting the correct DLLs.


Benefits

  • Time Efficiency: Reduces the need for repetitive adjustments across projects.
  • Version Flexibility: Ensures compatibility with multiple Acumatica versions.
  • Streamlined Management: Simplifies handling of version-specific dependencies.

This approach not only makes your codebase more robust but also prepares it for future changes with minimal effort.

Overall, I’m not a big fan of preprocessor directives and rarely use them in my projects. The reason is that they often conflict with the Single Responsibility Principle and Open/Closed Principle from the SOLID principles. However, this inheritance change in Acumatica is a perfect candidate for using preprocessor directives effectively, as it allows us to handle multiple versions cleanly and efficiently.

Wishing you successful and productive development!

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5