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; } }
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
Post a Comment