Resolving "The Field Cannot Be Bound to a FieldState" Error in Acumatica Modern UI
When extending the Modern UI in Acumatica to include custom fields, you may encounter the error:
"The field [FieldName] cannot be bound to a FieldState."
This error commonly arises when attempting to bind a custom field to the UI without defining it properly in the underlying data access class (DAC). Here’s a guide to resolve this issue.
Understanding the Error
This error occurs because Acumatica's framework requires all custom fields referenced in the UI to be defined in the corresponding DAC (Data Access Class) as part of its metadata. Without this, the framework cannot properly associate the field with its state and properties.
Reproducing the Issue
Suppose you have the following setup:
HTML File:
<template>
<field name="UsrICProjectID"
after="#columnSecond-DocumentHeader [name='ProjectID']">
</field>
<field name="UsrICProjectTaskID"
after="#columnSecond-DocumentHeader [name='UsrICProjectID']">
</field>
</template>
TypeScript File:
import { ARInvoice } from '../AR301000';
import { PXFieldState, PXFieldOptions } from 'client-controls';
export interface ARInvoice_GPGeneral extends ARInvoice { }
export class ARInvoice_GPGeneral {
UsrICProjectID: PXFieldState<PXFieldOptions.CommitChanges>;
UsrICProjectTaskID: PXFieldState;
}
Attempting to load the UI with these definitions will throw the error since the fields UsrICProjectID and UsrICProjectTaskID are not defined in the corresponding DAC.
The Solution
To fix this, you need to extend the relevant DAC and define the custom fields as follows:
DAC Extension:
using PX.Data;
namespace CustomizationNamespace
{
public class ARInvoiceExt : PXCacheExtension<ARInvoice>
{
[PXDBInt]
[PXUIField(DisplayName = "Custom Project ID")]
public virtual int? UsrICProjectID { get; set; }
public abstract class usrICProjectID : PX.Data.BQL.BqlInt.Field<usrICProjectID> { }
[PXDBInt]
[PXUIField(DisplayName = "Custom Project Task ID")]
public virtual int? UsrICProjectTaskID { get; set; }
public abstract class usrICProjectTaskID : PX.Data.BQL.BqlInt.Field<usrICProjectTaskID> { }
}
}
Key Points:
- Define Fields in DAC: Use the PXCacheExtension class to extend the base DAC and define your custom fields.
- Add Metadata: Use attributes like PXDBInt and PXUIField to define database and UI properties.
- Declare Field Classes: For each field, declare an abstract class to allow referencing in BQL queries.
Testing the Solution
Once the DAC extension is in place, reload the customization in Acumatica and navigate to the screen. The custom fields should now bind properly to the UI without errors.
Conclusion
Customizing the Modern UI in Acumatica can be straightforward if you follow the framework's requirements. Always ensure your custom fields are defined in the corresponding DAC before referencing them in the UI. This approach avoids binding errors and ensures a smooth development experience.