create table extension in d365fo


1.     Naming extensions (Table, View and Forms)

  • Suffix the name with the term Extension. For example, an extension of the InventLocation table should follow the pattern InventLocation.<Model>Extension. Example: InventLocation.WHSExtension
  • Don't name the extension just <Element that is being extended>.Extension. For example, an extension of the InventLocation table must not be named InventLocation.Extension, because the risk of conflicts is too high.

2.     Naming extension for logic on Tables, Classes or other elements

  • Start the name of the extension class with the name of the type that is being augmented and end the name with the term _Extension. For example: Extension class for ContactPerson table should start with the name ContactPerson and end with _Extension like ContactPersonWHS_Extension.
  • Use model name infix like <Element that is being Extended + Model Name_Extension> to avoid conflicts.

Extend Table:

To extend table go to table name, right click and select Create extension / Create extension in new project

  • Create Extension : This will add extension to the current project
  • Create extension in new project : It will create a new project and will add the extension.
No alt text provided for this image

Note:

  • Before creating table extension please check the respective table is part of current model package references. If table is in different model, then Create extension option will be disabled.
  • To enable this option, you need to update model reference. Go to tab Dynamics365 > Model Management > update model parameters
No alt text provided for this image
No alt text provided for this image

Modify existing fields in a table through extension

To modify properties on an existing field in a table, you must first create an extension for the table. You can modify the following properties:

  • Label
  • Help text
  • Country Region Codes
  • Extended Data Type – You can select only extended data types (EDTs) that are derived from the currently selected EDT. The lookup in the property sheet is filtered so that only those EDTs are shown. For example, to edit the EDT on the Width field in the InventTable table, you can create a derived EDT that is based on BOMMeasureWidth, and then modify the Extended Data Type property on the Width field in the InventTable extension. In this way, you can modify the look and feel of the Width field in the user interface when the new package is deployed.
No alt text provided for this image

Add fields to tables through extension

(Reference : https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/add-field-extension)

To add a new field to an existing table, you must first create a table extension. For example, to add a field that holds the radius of the released product, you must create an extension for the InventTable table in your model, as shown in the following illustration.

No alt text provided for this image

You can now add the field to the extension, just as you would add a field to a table in your model. You can use two methods:

  • In the designer, right-click the Fields node, select New, and then select the type of field to add.
  • Drag an existing Extended Data Type or Base Enumeration from your project onto the Fields node.

When you've finished, you can modify the properties of the new field. In the following illustration, only the Label property was modified.

No alt text provided for this image

You can now optionally add the new field either to one of the existing field groups or to a new field group that you create. In the following illustration, the Radius field was added to the PhysicalDimensions field group.

No alt text provided for this image

After compilation and synchronization of the database, you can see and edit the new field in the user interface.

No alt text provided for this image

Add indexes to tables through extension

To add an index to an existing table, you extend the selected table and then create an index just as you would create an index on a new table. You can add both new and existing fields so that they are part of the new index.

In the following illustration, an InventTable extension is used to define an index for a new field on the InventTable table.

No alt text provided for this image

Modify table properties through extension

You can now modify the following properties through the property sheet:

  • Created By
  • Created Date Time
  • Modified By
  • Modified Date Time
  • Country Region Codes

By setting the Created ByCreated Date TimeModified By, or Modified Date Time property to Yes, you help guarantee that a corresponding field is added to the table. Corresponding tracking information about the user is then stored in the table when records are created or updated. You can't set these properties to No if they are set to Yes on the base table.

By adding country or region codes to the list, you help guarantee that the corresponding table is also applicable when the system runs in the context of the specified country or region.

Add methods to tables through extension

To add method on the extension table we should create augmentation class.

For example, a new field that is named MyInventLocationId was added to the InventTable table through extension. A data event handler was also created for the Inserting event, and you must implement the logic of filling the new field there. To encapsulate that action, you will create a new method on InventTable and name that method myDefaultInventLocationId.

You first create a new class in the extension model. This class will augment the InventTable table and enable access to the table's fields and methods in a manner that is easy to read and understand. It's important that you choose the correct name for your augmentation class.

[ExtensionOf(tableStr(InventTable))]

final class InventTableMy_Extension

{

   public void myDefaultInventLocationId()

   {

       // This would have partner specific logic to initialize the new field.

       this.MyInventLocationId = this.inventLocationId();

   }

   // Other methods

}

These methods will then appear in IntelliSense for variables of the InventTable type, just as if they were defined directly on the table. This behaviour applies to both static methods and instance methods.

There are a few rules for augmentation classes:

  • They must be final.
  • They must be suffixed by _Extension.
  • They must be decorated with the [ExtensionOf()] attribute.

Comments