web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX7 Extension / Over-layering: onClicked Event handler in extensions

(0) ShareShare
ReportReport
Posted on by 501

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) // 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

   }
else
{
error("Some error message");
}

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Shahrukh Naeem,

    As you mentioned, you can subscribe only to pre and post events. You cannot modify method without overlaying.

    To deal with such kind of issues MS will add delegates for us but it's ongoing process and won't cover 100% of code, so overlaying is only 1 option that we have.

    However, if this code belongs to application platform  you probably want to file a case with MS because it will be locked for overlaying soon.

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Actually there is another option.

    You can "hide" standard method and override it with new one that will have all your changes. Please refer to my blog post for details ievgensaxblog.wordpress.com/.../ax-7-how-to-override-form-data-source-field-methods-without-overlaying

    It's talking about form data source fields but it is applicable to form controls as well.

  • Verified answer
    Shahrukh Profile Picture
    501 on at

    Hi ievgen,

    Thanks for your reply.

    And yes, i couldn't find any way to do this without overlayering, so what i concluded so far is that, we can't do it 100% without overlayering. May be in future we will have some more specific way of doing this, but for now we have two options.

    1. Do simple overlayering as we did in AX 2012 (which is not recommended)

    2. Do it with Delegates (even with delegates we are restricted to do some overlayering, but still it is recommended way)

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    From your code example, it looks like you want to execute code between the super() call and the clicked() method custom code. You're in luck, because that is exactly how the events work in AX7. The OnClicked() event is emitted by the kernel (i.e. the super() call). So, if you have a Clicked() method that looks like this:

    public void clicked()

    {

      info("method");

      super();

      info("method");

    }

    and a handler for OnClicked() that does info("handler"); then the output would be:

    method

    handler

    method

  • Mea_ Profile Picture
    60,284 on at

    Hi Joris de Gruyter,

    Looking at initial question I think author wants to skip sys code base on new condition and I don't think that throwing exception on pre event is a good practice.

  • Suggested answer
    Lauras U Profile Picture
    955 on at

    I had similar requirement.

    HcmWorker form button HideShowButton clicked method:

        [Control("Button")]
        class HideShowButton
        {
            void clicked()
            {
                super();
                partyForm.manageFields(true);
            }
    
        }

    requirement: execute custom code hiding some field after clicked. FormControlEventHandler FormControlEventType::Clicked executes after super() but before partyForm.manageFields(true);

    My solution was:

    [ExtensionOf(FormStr(HcmWorker))]
    final class HcmWorker_CustomerCode_Form_Extension
    {
        private xFormRun                    element;
    
        [FormEventHandler(formStr(HcmWorker), FormEventType::Initialized)]
        public void HcmWorker_OnInitialized(xFormRun _sender, FormEventArgs e)
        {
            FormButtonControl           hideShowButtonCtrl;
            element = _sender;
            //FormFunctionButtonControl   hideShowButtonCtrl;
    
            hideShowButtonCtrl = element.design().controlName( formControlStr(HcmWorker,HideShowButton));
    
            if(hideShowButtonCtrl)
            {
                hideShowButtonCtrl.registerOverrideMethod(methodStr(FormButtonControl,clicked),
                    formMethodStr(HcmWorker,hideShowButton_Clicked),this);
            }
        }
    
        [FormEventHandler(formStr(HcmWorker), FormEventType::PostRun)]
        public void HcmWorker_OnPostRun(xFormRun _sender, FormEventArgs e)
        {
            this.hideStdFields();
        }
    
        public void hideStdFields()
        {
            FormDataSource  dirPerson_DS = element.dataSource(formDataSourceStr(HcmWorker,DirPerson));
    
            dirPerson_DS.object(fieldnum(DirPerson,PersonalSuffix)).visible(false);
            dirPerson_DS.object(fieldnum(DirPerson,KnownAs)).visible(false);
            dirPerson_DS.object(fieldnum(DirPerson,ProfessionalSuffix)).visible(false);
            dirPerson_DS.object(fieldnum(DirPerson,PhoneticFirstName)).visible(false);
            dirPerson_DS.object(fieldnum(DirPerson,PhoneticMiddleName)).visible(false);
            dirPerson_DS.object(fieldnum(DirPerson,PhoneticLastName)).visible(false);
        }
    
        public void hideShowButton_Clicked(FormButtonControl _formButtonControl)
        {
    
            //super();
            _formButtonControl.clicked();//super and partyForm.manageFields(true); call
            this.hideStdFields();
    
        }
    
    }
    


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans