Add a table extension to a project

Completed

If you want to modify the fields, field groups, indexes, mappings, or relations of a table, you can create an extension of the table and make the necessary changes. Additionally, you can add fields and add fields to field groups.

Fields can be added by either right-clicking the Fields node of the table and selecting New, or by selecting and dragging a field from the AOT or Solution Explorer window to the Fields node of the table. After the field is added to the table, you can select and drag it to an existing field group, or you can create a new field group and drag the field to it. The added field and/or field group will be shown in bold type, while the existing fields and field groups will be displayed in italic type.

The following is an example of adding the AccountNum field from AOT > Data Types > Extended Data Types to the Fields node of the FMCustomer.myExtension table.

This is a screenshot from Visual Studio showing the AccountNum field
has been added to an extension of the FMCustomer
table.

Table indexes

An index can speed up database searches. If you add fields to a table, you might also want to add a dedicated index. You can use existing fields and new fields in creating the index. After you have created an extension of your desired table, you can add an index in the same manner that you would add an index to a new table. You cannot use an extension to create a unique index. That type of development is intrusive and therefore not allowed.

Like adding an index to a table after adding new fields, you might also need to create a relation if the new field should be linked to another table. Defining relations can help you guarantee referential integrity by describing the link between the two tables. Adding a new relation to an extended table follows the same process as adding a relation to a new table.

You can adjust the table's or the individual field's label or help text, as well as other available properties. If you set the Created By, Created Data Time, Modified By, or Modified Date Time property to Yes, it will add corresponding tracking information about the user to the table when records are created or updated. Not every property that is listed in the Properties window can be adjusted. For example, the tracking properties that were mentioned cannot be changed to No if they are set to Yes on the base table. If a property appears dimmed, it isn't editable.

Table business logic

Event handlers can also be implemented and are called from the base implementations of the table methods. First, you need to create a new class that extends the desired table and enables access to its fields and methods. The class should be decorated with the final and [ExtensionOf()] attributes and have the _Extension suffix. The following code sample shows how to create a new class that extends the table InventTable.

[ExtensionOf(tableStr(InventTable))]
final class InventTableMy_Extension
{
	public void myDefaultInventLocationId()
	{
		//Contains organization-specific logic to initialize the new field here.
		this.MyInventLocationID = this.inventLocationId();
	}
}

Next, you will add methods to the augmented class and use your new method from an event handler. The following is an example of an InventTable class event handler.

class InventTableMy_EventHandler
{
	[DataEventHandler(tableStr(InventTable), DataEventType::Inserting)]
	public static void InventTable_onInserting(Common sender, DataEventArgs e)
	{
		InventTable inventTable = sender as InventTable;
		// Call the method as if it was defined directly on InventTable.
		inventTable.myDefaultInventLocationId();
	}
}