To Set a Default Value
When a user creates a new record of a business entity through a form of MYOB Acumatica, you might need to set a default value for a data field. You use the PXDefault attribute for a data field to set a constant as the default value, or you provide a BQL query to obtain a value from the database or data records from the cache. The default value is assigned to the field when a data record holding this field is inserted into the cache.
Note:
If the default value is taken from a field that can be auto-generated by the database
(such as an ID), you should use the PXDBDefault attribute instead of the
PXDefault attribute.
You can set a default value for an original or custom text field on the DAC and graph levels.
The following sections provide detailed information:
To Set a Default Value for an Original Field on the DAC Level
To set a default value for a field used on multiple forms, you should customize the
original attributes of the field in the data access class extension. To do this, perform the
following actions:
- Open the field in the Data Class Editor, as described in To Customize a Field on the DAC Level.
- In the Customize Attributes box, select Append to Original.
- In the edit area below the box, add the PXDefault attribute and define a default value for the attribute.
- Click Save on the editor toolbar to save your changes to the customization project.
To Set a Default Value for an Original Field on the Graph Level
To set a default value for a field used on a single form, you should customize the original
attributes of the field in the graph extension. To do this, perform the following
actions:
- Create the code template that includes the original attributes of the field and the DACName_FieldPropertyName_CacheAttached() event handler, which replaces the attributes within the graph, as described in To Customize a Field on the Graph Level.
- By using the Code editor, replace the original attributes in the template, as shown in
the following code
snippet.
[PXMergeAttributes(Method = MergeMethod.Append)] [PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)] protected void DACName_FieldPropertyName_CacheAttached(PXCache cache) { }
- Click Save on the editor toolbar to save your changes to the customization project.
To Set a Default Value for a Custom Field on the DAC Level
If you need to set a default value for a custom data field on the DAC level, you add the
PXDefault attribute and define a default value for the attribute in the
edit area of the Data Class Editor, as shown in the following screenshot.