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






No comments:

Post a Comment

Note: only a member of this blog may post a comment.

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...