In the previous articles, we have already discussed Custom Table Methods Through Extension in Microsoft Dynamics 365 Finance & Operations. In this article, we are discussing one of the interesting topics called Chain Of Commands (CoC). Before reading the concept of Chain Of Command (CoC) in D365, we just have a look at the history of the re-architecture process of D365 by Microsoft.Â
In the previous versions of 2012 and before a programmer can change the Base Microsoft's source code directly from the developing environment. Microsoft identified the problem and from the next version, Microsoft re-architected the code and made it so that Base Microsoft's source code and Objects cannot change directly in D365.
"What was the problem when a user modify the Base Microsoft's source code or Objects?". Microsoft releases new features and hotfixes as a part of product improvement. In these cases the new code should be merged with customized code, depending on the depth of the customization the complexity of the merging process will increase. So Microsoft found this difficult and removed the feature. This benefits the users to update the hotfixes and features updates of the product from Microsoft very fast, securely, and safer than ever could before.If you are a beginner or learner use Microsoft's free VM, there you can access both the Technical and Functional environments for developing your knowledge in D365 Finance and Operations.
What is the Chain of Command in D365?Â
Chain of Command is the term that describes how we customize or extend, the base Microsoft code in Microsoft Dynamics 365. Microsoft’s base objects and code cannot be changed directly in D365. However, we are able to make changes to separate objects and classes that are then combined with the existing base object to form the final version.
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; } }
So we can go through the example of how to extend and overwrite an existing method with a Chain Of Command (CoC). For this, we are extending the Data Method ItemName of the Form SalesTable with the help of the Chain of Command.
Create Model
Let us create one model D365SnippetModel,Â
for this go to Dynamics 365 > Model Management > Create Model
Create Project
Create one project Under the model D365SnippetModel, here I created one project with the name ExtensionProjectCoC.
Extend the form SalesTable
As we already read we are extending the Data Method ItemName of the form SalesTable with the help of Chain of Command. So the next step is to extend the form SalesTable for this,
Go to View > Application explorer > User Interface > Forms > SalesTableÂ
Right-click on the SalesTable and choose the option to create an extension.
The Data Method ItemName of the Form SalesTable is listed under the grid view SalesTable > SalesLineGrid > Item Name. You can find this data method name under the properties list of ItemName.Â
finding the data method ItemName is a little difficult because the form pattern controls are very complex for the form SalesTable. So search the SalesLineGrid in the search area of the design view of the SalesTable.
Create Class
The next step is to create an extension class SalesLine_Extension for implementing the CoC method for this,
Right-click on the Project > Add > New Item > Code > Class
After creating the class SalesLine_Extension write the x++ code for implementing the CoC.
Before writing the x++ code for implementing the CoC we must know some rules,
- The name of the class you created for implementing the Chain of command must end with the _Extension keyword. In our example the class is SalesLine_ExtensionÂ
- Must add the attribute [ExtensioOf(TableStr(<name of the Base Class>))]
- The classes must start with public access modifier.
- The keyword "final" needs to be used in the class.
- The extension method name should be exactly the same as it appears in the Base Class.
- The base class method must be called inside your extension method and the method name call using the next keyword. Var v= next methodName();
The output of the Extension Project
Go to Account Receivables > Customer Order > Double Click on customer order.
it will display the Header and Line of items. There you can find out the output of our customization, we added the string "D365 Snippets" with every item.
Conclusion
Now you have learned the basic concept and example of customization using Chain of command . Based on the complexity of the project , the complexity of customization of using Chain of command will be different . You can refer this article for getting the basic concept of COC. if you like this article please share to your friends and your comment will be very valuable for improving the quality of the articles.
Nice article
ReplyDelete