Chain Of Command In Microsoft Dynamics 365

Fareeha Sattar Shaikh
3 min readApr 26, 2022

--

The base code provided by Microsoft for tables, forms, and entities can not be edited directly. To add custom business logic or something special for our specific business requirement we might feel the need to edit an already present method or add a new method too.

To fulfill this need, we use the concept of chain of command. Chain of command provides the capability to extend or customize the Microsoft base code by adding separate classes of extension.

There are multiple objects which can use the concept of chain of command, the ones which are mostly used are:

  • Classes
  • Tables
  • Data Entities
  • Forms

Examples Of Different Objects

Example Of Table

Taking an example of CUSTTABLE, this is Microsoft provided table. The code behind this table can’t be edited, so to add our custom logic we can create an extension by the naming convention of ‘CustTable_Extension’ The important thing to be noted here is, that we have to add ‘_Extension’ at the end of our new class name.

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
void modifiedField()
{
next modifiedField();
//Write your own custom logic here
}
}

As it can be seen in the above example, the keyword ‘ExtensionOf’ is used, and the keyword ‘tableStr’ because here an extension class of a table is being created. Moreover, the final keyword is a must to put in the class definition. Lastly, next modifiedField(), this means that first, we are calling the basic functionality which is already provided then we are writing our logic. It is a must to call next otherwise, the code wouldn’t be compiled. Calling the next before or after custom logic depends on the requirement, but calling it is a must.

Example Of Form

Taking example of SalesTable form, this is microsoft provided form to display sales orders. We can create its extension class named as ‘SalesTable_Extension’ to add custom logic.

[ExtensionOf(formStr(SalesTable))]
final class SalesTable_Extension
{
void init()
{
next init();
//Write your own custom logic here
}
}

As it can be seen in the above example, because an extension class of form was being created keyword of ‘formStr’ is used.

Example Of Data Entity

Taking example of CustCustomerV3Entity, microsoft provided entity for import/export of customer data. We can create its extension class names as ‘CustCustomerV3Entity_Extension’ to add custom logic.

[ExtensionOf(tableStr(CustCustomerV3Entity))]
final class CustCustomerV3Entity_Extension
{
void mapEntityToDataSource()
{
//write custom logic here
next mapEntityToDataSource();
}
}

Summary

The Chain of command can be used to add custom logic and custom validations before or after the base code. Either put the next call before custom code, or after depending upon the requirement. Also, in the naming convention sometimes the form name and table are the same such as SalesTable. So, to avoid confusion, the extension class name can be defined in the format SalesTable_Table_Extension or SalesTable_Form_Extension. It is not mandatory but can be followed as per convenience.

--

--

Fareeha Sattar Shaikh

Software Engineer | Microsoft Dynamics 365 Technical Consultant | Creative Writer