Skip to main content

Dynamics 365 for finance & operation/AX 7- Chain of command

Dynamics 365 for finance & operation/AX 7- Chain of command

In past couple of releases and updates from Microsoft, Dynamics 365 for finance & operation aka AX7 came up with a lot more new Extension feature. Current version came with a lot of hard sealed version and few are soft sealed. Hard seal packages will not allow a developer to make any changes in the existing code but still this flexibility is there with the soft sealed packages. But it's best practices to avoid changes or modifications in the existing piece of code because you never know the next version will come with all hard sealed packages.

So there are multiple extension features that we are already aware of like delegates, events and pre & post event handlers. As part of update 9, Microsoft has given one more extension possibility which is Chain of command. Now Pre & Post functionality can be used in Extensions in more easier way. And it also provides developers flexibility to work with Protected methods and variables directly in the Extension class.

Now lets understand how Chain of commands works with the following example:

Suppose we have a standard class "TestCOC" in which one method we need some customization.

Class TestCOC
{
        public void run()
        {
                 This.testMethod();
        }
        protected void testMethod()
        {
                info(“Inside main testCOC”);
        }
}


Now there is a child class which extends TestCOC i.e. ChildTestCOC.



class ChildTestCOC extends TestCOC
{
protected void testMethod ()
{
                    info("child class before super");
                    super();
                    info("child class after super");
}
}

Lets say you want to write some custom code in child class’ testMethod(). How you’ll achieve it using Chain of command?

First you need to create an extension class for your child class and have to create same method with exact signature.

[ExtensionOf(classStr(ChildTestCOC))]
Final class ChildTestCOC_Extension
{
protected void testMethod ()
{
          //Insert before actual method execution
                    info("Custom logic before super()");
                   
                   next testMethod();

                   //insert logic after actual method execution
                    info("Custom logic before super()");
}
}

The method we added here is the new chain of command definition. We use exactly the same notation as the original method we are extending and add a mandatory “next” keyword to the call which will wrap our extension code around the extended method. This next keyword separates the pre and post parts of our extension and mandatory to be called inside the chain of command method. Next call cannot be placed in any kind of program block like if() block or while block. When you call next(), it checks for other extensions in the queue and runs them in random order, lastly running the base code.

Not only methods, Chain of commands also shares the access for protected variables from your base code/class.

Comments

Popular posts from this blog

Get account Structure ranges set in AX Ledger

How to pass Account Structure ranges set in AX Ledger to an external system. Recently I have got a requirement where I have to populate same set of main account and financial dimension values to an external system using integration off course, which I have set in AX Ledger. The difficulty in this scenario was, how to get the valid set of main account and financial dimension values from AX.  Because AX gives us 'Segmented Entry Controls' where we just have to use the field as a segmented entry control and valid values will populate according to the Account Structure set in Ledger.  I have created a service class which extends "DimensionValueService" public class CMCDimensionValueService extends DimensionValueService {     // Insert list of valid main accounts to 'DimensionValueContract'     private void insertMainAccountValueLocalList(List                       _dimensionValueList,                                                  Dime

Mass cheque printing in AX7/Dynamics 365 for finance & operation

AX7/Dynamics 365 for finance & operation: How to avoid user interaction while printing multiple cheques(Mass cheque printing) You all might be aware of the ‘Generate Payment’ functionality available in Dynamics AX. This function we use to generate/print cheques. The process is to create one payment journal, add few transactions with mode of payment as ‘Cheque’ then go for ‘Generate Payment’ option available in the drop down of ‘Function’ menu item button. Process is specific to print one cheque at a time for a single journal. Recently I came across a requirement where I had a customized form which contains multiple journal records and I have to add the ‘Generate Payment’ button on the form to allow user to print the checks for journals, and also allow user to select multiple journal records at the same time to print cheques and avoid user interaction with the system for each cheque. The major challenge here was, how to handle user interactions everytime to print multiple

Hierarchy conflicts in AX 7 during migration from other AX versions and it's resolution - Delegates and Handlers

Delegates and Handlers in AX 7(Hierarchy conflicts resolution) Hi, We recently did a migration of our AX 2012 solution to AX 7, and while doing so one of the major challenge that we have faced are hierarchy conflicts. I'll be discussing here on the same. First of all we need to know that what is a hierarchy conflict. Coming to the AX 7 architecture, Application stack is divide into three basic packages. These are- 1: Application Platform 2: Application Foundation  3: Application Suite As shown in the above image, Application platform is the base package which contains Runtime and data access , work flow and services etc. and on top of it we have application foundation which contains organisation model, number sequence and GAB etc. and at the top we have Application Suite and Fleet Management. To understand the concept of these packages in depth you can follow the below link- Architecture changes in AX 7 All three models follows a hierarchy. Application p