Skip to main content

Fundamentals of Chai of Commands in microsoft D365 for Finance and operations

What is Chain Of Commands(COC)?

Chain of command describes how we will extends or customize the Microsoft base code in Dynamics365. we can not perform any customization on Microsoft base objects/standard objects and codes directly. But we can make changes to separately on objects and then those changes can combine with base objects to make final version.

Why Microsoft introduced the COC concept?

In Ax Dynamics 2012 and earlier versions developers are able to directly modify  base Microsoft standard code for any customization and modification. There is a problem by doing direct modification of base code is that when Microsoft releases a hot fix or new features, the modified code need to be remerged with new base code other wise the clients cannot have proper intended purpose of modification the merging is time consuming process. So that Microsoft re-architected the code in such a way the base objects cannot be modified directly.

When to use Chain of Commands?

Standard Microsoft objects can be modified by using the tool that Microsoft has provided is  "extend", by using this extend tool we can modify Tables, forms and AOT objects. However extending of X++ base code we need to use Chain of Command (COC), or Event handler.

Event handlers still have their places and support as a developer I personally prefer chain of command.

Example With Basic Syntax

[ExtensionOf(classStr(CustTable))] public final class CustTable_Extension { public display str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } }

In the above example, any time the system calls the doSomething method it will acctually call anychain of command class with doSomething method. This will call your custom code along with base
code

This is extremely powerful as your custom code can do the following:

  • Take any values passed in as parameters, and change them before they call the base Microsoft code.
  • Add code that runs in addition to the base Microsoft code.
  • Retrieve any return value from the base Microsoft code, and potentially change the value before returning it to the code that called this method.

Rules for creating Chain of Commands (COC)

1. The name of the class we are creating for implementing COC should be end with _Extension,

in above example CustTable_Extension is the class.

2. Must use the Attribute [ExtensionOf(classStr(Name of the Base Class))]

3. The Class must have public access modifier

4. The keyword final be used in this class

5. The extension method name and base class name should be exactly equal as shown in above example

6. Base Class method must be called inside the extension method. And the method and method name using

next key word.

Objects that can use Chain of Command

1.Classes

2. Tables

3. Forms

4. Data Source on a Form

5. Data Field on a form

6. Control of a form

7. Data Entities

Conclusion

We have seen that how Chain of command is usefull to add custome code to the base code

and in the example you have seen basic class creation. In the upcomming articles we will discuss

about how to create chain of command (Coc) classes for each base type of objects.



Comments

Popular posts from this blog

Fixing the “Can’t Stop DynamicsAxBatch” Error During Admin User Provisioning in Dynamics 365 F&O

 If you're working with Microsoft Dynamics 365 for Finance and Operations (D365 F&O) and encounter the dreaded error “Can’t stop DynamicsAxBatch” while using the Admin User Provisioning Tool , you're not alone. This guide walks you through a quick and effective solution to resolve the issue and get back to work without delays. đź› ️ What Is the Admin User Provisioning Tool? The Admin User Provisioning Tool is used to register a user as an administrator on a D365 F&O instance—typically for development and customization purposes. You provide your Azure AD credentials (email address) to gain admin access. ❌ The Problem: “Can’t Stop DynamicsAxBatch” Error While registering via the Admin Provisioning Tool or attempting to stop the service manually through Windows Services , you might encounter an error stating: “Can’t stop DynamicsAxBatch” This error prevents you from proceeding with the registration process.  The Solution: Step-by-Step Fix  Step 1: Try Stoppi...

How to get batch header and recurrence information in service class for sysoperation frame work in D365 F&O

  BatchHeader batchHeader         = this.getCurrentBatchHeader();         int         timeUnitsSelected   = 0;         if(this.isExecutingInBatch())         {             RefRecId batchRecId = batchHeader.parmBatchHeaderId();             BatchJob batchJob;             select firstonly batchJob             where batchJob.RecId == batchRecId;                      SysRecurrenceData recurrenceData = batchjob.recurrenceData;             SysRecurrenceUnit timeUnits = conPeek(recurrenceData, 7);             timeUnitsSelected = timeUnits;         }

Table Keys: Surrogate, Alternate, Replacement, Primary, and Foreign

Primary key A primary key is one type of key. The other type of key is an alternate key. There is a maximum of one primary key per table , whereas a table can have several alternate keys . The primary key is usually the type of key that other tables, called child tables, refer to when a foreign key field in those other tables need a relational identifier. Starting in Microsoft Dynamics AX 2012 the primary key for every new table is always enforced by an index that has exactly one field. The one field is usually an incremented number or a completely meaningless number that is generated by the system. For new tables the default is a primary key based on the RecId field. This is represented as the surrogate key in the user interface. The following table describes the  PrimaryIndex   property and other major properties that are related to keys. Property Description PrimaryIndex The drop-down list contains the surrogate key plus every index on the table that has its  Alternate...