Acumatica Attributes in DAC Code

By | February 2, 2024

Acumatica provides a powerful framework for creating and customizing data structures through the use of Data Access Classes (DACs). One of the key features that contribute to the flexibility and extensibility of Acumatica data structures is the use of attributes.

In this blog post, we will dive into the world of Acumatica attributes used in DAC code, exploring their significance and types. Let’s see how attributes enhance the definition and behavior of DAC fields.

Attributes:

Attributes in Acumatica are metadata tags applied to DAC fields, providing additional information about how the field should be treated or presented. They impact various aspects, including user interface rendering, validation rules, and database interactions.

Commonly Used Attributes

1. PXDBString

The `PXDBString` attribute defines a string field in the database. It allows you to specify the maximum length, whether the field is a key, and whether it should be stored as Unicode.

Example:

 [PXDBString(30, IsUnicode = true, InputMask = “”)] [PXUIField(DisplayName = “Customer ID”)]

2. PXDefault

The `PXDefault` attribute sets the default value for a field. This is useful for fields that should have a predefined value when a new record is created.

Example:

[PXDefault(“NEW”)]

[PXDBString(2, IsFixed = true)]

[PXUIField(DisplayName = “Status”)]

3. PXUIField

The `PXUIField` attribute controls the appearance and behavior of fields in the user interface, including labels, visibility, and enabled/disabled states.

Example:

[PXUIField(DisplayName = “Customer Name”, Visibility = PXUIVisibility.SelectorVisible)]

[PXDBString(60, IsUnicode = true)]

4. PXSelector

The `PXSelector` attribute associates a field with a selector control, providing a list of values for the user to choose from.

Example:

[PXSelector(typeof(Search<InventoryItem.inventoryID>))]

[PXDBInt]

[PXUIField(DisplayName = “Inventory ID”)]

 Advanced Attributes

  • PXFormula

The `PXFormula` attribute allows you to define calculated fields based on formulas involving other fields within the DAC.

Example:

[PXFormula(typeof(Switch<Case<Where<Current<SOOrder.orderQty>, Equal<decimal0>>, int1>, int0>))]

[PXInt]

[PXUIField(DisplayName = “Zero Quantity Flag”)]

  • PXDimensionSelector

The `PXDimensionSelector` attribute provides a specialized selector for dimension fields, ensuring adherence to dimension rules.

Example:

[PXDimensionSelector(INItemSite.dimension, typeof(Search<DimensionValue.valueID, Where<DimensionValue.dimensionID, Equal<INItemSite.dimension>>, OrderBy<Asc<DimensionValue.sortOrder>>>), typeof(DimensionValue.valueID))]

[PXDBString(30, IsUnicode = true)] [PXUIField(DisplayName = “Location ID”)]

Greytrix, with its 24+ years of expertise as the Sage Development partner, extends its mastery to bring Acumatica to modern businesses. Greytrix offers complete end-to-end professional services for Acumatica, ranging from development, support, technical assistance, consulting, and system integrations.