To Add a Custom Column to an Existing Table
You use the Database Scripts page of the Customization Project Editor to add custom columns of an existing table of MYOB Acumatica to a customization project. If you add custom fields to a data access class by using the Data Class, you do not need to add the custom columns to the database table manually; the MYOB Acumatica Customization Platform adds these columns automatically. You may need to add a column manually if you added a custom field to a data access class in code.
We recommend that you not write custom SQL scripts to add changes to the database schema. If you add a custom SQL script, you must adhere to platform requirements that apply to custom SQL scripts, such as the support of multitenancy and the support of SQL dialects of the target database management systems. If you use the approach described in this topic, during the publication of the customization project, the platform generates SQL statements to alter the existing table so that this statement conforms to all platform requirements.
To Add a Custom Column to an Existing Table
To add a custom column, do the following:
- Open the customization project in the Customization Project Editor. (See To Open a Project for details.)
- In the navigation pane, click Database Scripts to open the Database Scripts page.
- On the More menu (under Actions), click Add Custom
Column to Table.
The Add Custom Column to Table dialog box opens.
- In the dialog box, specify the table to which the column should be added and the name and type of the new column, and click OK.
The MYOB Acumatica Customization Platform adds the columns to the customization project as a Table item.
To Specify the Default Value for a Column
By default, the system adds a custom column that can have Null values. If you need to add a column that does not allow Null values and you want to specify the default value for this column, do the following:
- Add a custom column, as described in the previous section.
- In the main menu of the Customization Project Editor, click
The Edit Project Items page opens.
. - In the table on the page, click the row with a database table that contains the custom column for which you want to specify the default value.
- In the Source section of the page, do the following:
- Remove the
AllowNull
attribute, or specify the False value for it. - Add the
DefaultValue
attribute.
- Remove the
- Save your changes.
The following code shows the 0 default value being specified for the
UsrFlag
column of the ARTran
table. The type of the
column is bool.
<Table TableName="ARTran">
<Column TableName="ARTran" ColumnName="UsrFlag" ColumnType="bool"
DefaultValue="0" DecimalPrecision="0" DecimalLength="0" IsNewColumn="True"
IsUnicode="True" />
</Table>
The following code shows the test default value being specified for the
usrTest
column of the ARTran
table. The type of the
column is string.
<Table TableName="ARTran">
<Column TableName="SOOrder" ColumnName="usrTest" ColumnType="string"
DefaultValue="'test'" MaxLength="10" DecimalPrecision="0"
DecimalLength="0" IsNewColumn="True" IsUnicode="True" />
</Table>