ACUMATICA

Acumatica Custom Fields & Validation

February 7, 2024 13 min read

Introduction

Acumatica allows you to extend standard screens and data access classes (DACs) with custom fields. This guide covers how to add custom fields and implement validation logic.

Creating Custom Fields

Use Acumatica's customization project to add custom fields:

// Add custom field via DAC Extension
// Step 1: Create extension class for the DAC

[PXCacheExtension(typeof(ARCustomer))]
public class ARCustomerExt : PXCacheExtension<ARCustomer>
{
    [PXString(50)]
    [PXUIField(DisplayName = "Custom Field")]
    public string UsrCustomField { get; set; }
    
    public abstract class usrCustomField : PX.Data.BQL.BqlString.Field<usrCustomField> { }
}

DAC Field Extensions

Extend existing DACs with additional fields:

// Extending InventoryItem with custom fields
[PXCacheExtension(typeof(InventoryItem))]
public class InventoryItemExt : PXCacheExtension<InventoryItem>
{
    [PXDecimal(2)]
    [PXUIField(DisplayName = "Custom Price")]
    public decimal? UsrCustomPrice { get; set; }
    
    [PXBool]
    [PXUIField(DisplayName = "Is Special Item")]
    public bool? UsrIsSpecialItem { get; set; }
    
    public abstract class usrCustomPrice : 
        PX.Data.BQL.BqlDecimal.Field<usrCustomPrice> { }
}

Field-Level Validation

Implement field-level validation using attributes:

// Using PXString with validation
[PXString(10, InputMask = "##-####-###")]
[PXUIField(DisplayName = "Tax ID")]
[PXRegex(@"^\d{2}-\d{4}-\d{3}$", 
    Message = "Tax ID must be in format XX-XXXX-XXX")]
public string UsrTaxID { get; set; }

// Using PXInt with range validation
[PXInt]
[PXUIField(DisplayName = "Priority")]
[PXMinValue(1)]
[PXMaxValue(10)]
public int? UsrPriority { get; set; }

Business Rule Validation

Implement complex validation in RowPersisting events:

protected void ARCustomer_RowPersisting(PXCache sender, 
    PXRowPersistingEventArgs e)
{
    ARCustomer row = (ARCustomer)e.Row;
    
    if (row.CreditLimit < 0)
    {
        sender.RaiseExceptionHandling<ARCustomer.creditLimit>(
            row, row.CreditLimit,
            new PXSetPropertyException("Credit limit cannot be negative"));
    }
    
    if (string.IsNullOrEmpty(row.CustomerName))
    {
        throw new PXRowPersistingException(
            typeof(ARCustomer.customerName).Name,
            null, "Customer name is required");
    }
}

Summary

Acumatica provides flexible ways to add custom fields and implement validation. Use DAC extensions for custom fields and event handlers for complex business rules.

For more Acumatica guides, see DAC Extensions Best Practices.