Search code examples
eventsextension-methodsaxaptadynamics-ax7

Writing event handlers in extensions in AX7


I am working in Dynamics AX7 form development. I have to write code in 'Clicked' method of a button, but there is already some 'Sys Layer' code in 'Clicked' method. I have to apply some conditions on it. But I don't want to do 'over-layering', i have to do it with Extensions, but if I write code in onClicked event, the problem is, my code runs before or after the sys-layer code, but i need to apply some conditions on that sys-layer code.

my question is, can we achieve this logic with extension event handlers ? I have already done it with over-layering, but I need to do it with extensions. So is it possible to do it with extensions ?

Code is added below.

void clicked()
{      
       super();

       // My logic will be written here

       if(result == true) //This is my code, based on above logic I applied this check
       {
           // start of sys layer code
           remainSalesPhysical.realValue(0);
           remainInventPhysical.realValue(0);
           if (formCtrl)
           {
               formCtrl.cancelLine();
           }
           element.closeOk();
           // end of sys layer code    
       }                                      //this is my code
       else                                   //this is my code
       {                                      //this is my code
           error("Some error message");       //this is my code
       }                                      //this is my code
}

Solution

  • I have searched about it and what i concluded so far is that, we can't do it 100% without overlayering. We have Pre and Post events but these are unable to cater the above mentioned problem, May be in future we will have some more specific way of doing this, but for now we have three options.

    1. Do overlayering as we did in AX 2012 (which is not recommended)
    2. Do it With Delegates (even with delegates we're restricted to do some overlayering, but it is recommended way)
    3. You can also hide that button and replace it with your own button, but it will work only for Form Controls, we can't do it for methods, as you can't avoid calling them.

    I solved my problem using delegates. Here is a Helpful link I found about it and it helped.

    https://ievgensaxblog.wordpress.com/2016/05/01/ax-7-how-to-override-form-data-source-field-methods-without-overlaying/