1

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
}
Shahrukh Naeem
  • 61
  • 1
  • 10

2 Answers2

0

Yes and no. If it's just a button then the super() doesn't really do anything, so you can do a pre event handler.

If it's a menu item button, where the super() calls a class, then you would do a post event handler to the class and not the button, so that way your logic runs immediately after the super() call.

And in your class, you can do something like formRun = _xppPrePostArgs.getThis() and then if (formRun.name() == formStr(SalesTable)) or any number of things if the class has multiple entry points.

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Thanks @Alex, Yes you are right, we have pre and post events, but specifically for the above mentioned problem these events can't help. So i did it with delegates. but still delegates required some overlayering, but we need to stick with it until MS introduces some new way of doing it. – Shahrukh Naeem Aug 13 '16 at 11:37
  • Without seeing more of your code, I don't see why you can't do it without over-layering. The `super()` does something, so to get your code where you need, you just need to get `post` of the `super()` via whatever the button actually does. – Alex Kwitny Aug 13 '16 at 16:58
  • Kindly have a close look at my code again. I've mentioned every thing. There is already some code of sys layer after super() call. and I want that code inside 'if' condition. how can i do that ? – Shahrukh Naeem Aug 13 '16 at 18:23
  • You haven't answered what type of button it is. But one thing you could do is just hide the button and replace it with your own, then have your own button call that button. There are ways to do it. It sounds like you have your solution that you want though. Good luck. – Alex Kwitny Aug 13 '16 at 20:39
  • It is simple button, not Menu item Button. And thanks for sharing the other option of hiding the button. yes, it is also an option for form controls that we can hide them, but if we want to do the same for any predefined method (e.g. mcrSetEditGiftCard method of salesTable) do we have any option for that ? – Shahrukh Naeem Aug 15 '16 at 12:11
0

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/

Shahrukh Naeem
  • 61
  • 1
  • 10