Showing posts with label Chain of command. Show all posts
Showing posts with label Chain of command. Show all posts

Thursday, 27 December 2018

Chain of Command (COC) - New ability to extend data source and data field methods

Microsoft introduced the new feature of extensibility which is known as Chain of Command (COC). This feature allows to use or call protected methods or members without making them hook able. Or We can say that it allows to extend the logic of public or protected methods without the need to event handlers. It is great feature for developers to do work with extension and avoid overlayering. It has made much easier for us to add pre and post functionality than previously used event handlers.

In Platform update 15 the concept of COC was implemented to class, tables and forms but with the release of October 2018 they have extended this capability and introduced COC  across data source fields/methods which was previously missing.

Note: If you want to use COC you need to declare your class as final and your method should always contain next keyword.

The next keyword behaves like super and it defines execution of your extended code. If next is called after your code then it will behave like Pre handler which means your logic will execute first then original method logic. If next is called before your code then it will behave like Post handler which means original method logic will execute first then your custom logic.

Let's take a example of item group setup. Suppose I want to create new a item group and set it name value on default basis at a time of modifying item group id field. But we want to execute first original method logic then our custom logic. So here we will follow post event handler concept using chain of command.

Create a new class which will be final and add below logic in it. Remember you need to create new class for every object you want to extend.



Tuesday, 16 October 2018

Chain of command Or Method wrapping in D365

Microsoft has improved the functionality of class extension for D365FO by adding wrap logic around methods which are defined in the base class that you are augmenting. Apart from this now you can extend the logic of public and protected methods without using event handlers. After wrapping a method, you can access its public and protected methods and variables of that class without making them hookable or using pre or post event handlers.

Note : Features is available in Extension (PU8).


Step 1) I have created a class in model A and add a protected method in it.











Step 2) Create a new class in Model B that will be extension of  DemoParentCOC class and add below code in it.
You will see here that you are now able to call protected method by using next keyword.
The calling stack will execute in such a way that it will first go to Standard method and finds out if there is any extension method. If it will find out any extension then it will call to it. In extension method again it will try to find out  any other extension method. If their is not any  second extension method then it will call first standard method logic.  After executing logic of standard method COCTest of DemoParentCOC class, it will call remaining code of extension method.

If we did not define NEXT word method else it will not execute standard method.















Step 3) After executing the class, it output will be in this way:
- Info : "COC Started" printed
- Info : "Base class" printed
- Info " "COC ended" printed






Custom Business events Part 3 - (Activate custom business event) in D365 F&O

 In this blog we will discuss about the steps to activate a custom business in D365 F&O. As we know that business event catalog does not...