Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Can't access clicked method of a button from the class of a extension form

(0) ShareShare
ReportReport
Posted on by 22

Hello, 

In D365, I have a class of an extension form. From there, I am trying to call clicked method of a button in the form extension. But ax isn't executing the piece of code inside the clicked method. When I try to debug and check, I see that although ax doesn't go inside the clicked method.

Even previously, I had got this kind of issue in the same form but that was in the modified method of a string control. As an workaround, I called stringControl.haschanged() method before calling the modified method. Once I added that, ax started executing the code inside the modified method.

Both the methods get called correctly in our 2012 environment. 

Anyone has any idea regarding this? Is it happening because of some property? Thank you in advance. 

FYI - I am new to dynamic 365 and a vendor has upgraded our ax 2012 to dynamic 365. 

  • Suggested answer
    Sukrut Parab Profile Picture
    71,687 Moderator on at
    RE: Can't access clicked method of a button from the class of a extension form

    I dont see any issue in the code. Are you using a button or menuitem button ? depending on that you can use formButtonControl or formMenuButtonControl.   You can also use registerOverrideMethod in your scenario.

    for example ,

    formButtonControl.registerOverrideMethod(methodStr(formButtonControl,Clicked),#clickedMethod,this);

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Can't access clicked method of a button from the class of a extension form

    I don't think that the issue is in your code. Could be a platform bug / issue. You can create a MS support case. 

    But, since I think you're using the button in a way that it's not really intended for, they might simply repeat my suggestion to implement it in a neater way. Or, you could have it fixed in a couple of months if you're lucky. Anyway your code would already work by now if you changed it and moved the business logic to a separate class :) sorry for repeating myself, I will stop it now. 

  • Satyaprajna Das Profile Picture
    22 on at
    RE: Can't access clicked method of a button from the class of a extension form

    Hello Gunjan,

    Yes. It executes when I click the button. The issue here is that in D365 or at least in our D365 environments, whenever a control level method is called from a form level method, the code inside the control level method doesn't execute. Even when I press f11 during debugging, it doesn't go inside the control level method. So what I am wondering is if this issue is only being faced by me or anyone else. If only I am facing the issue issue then I want to know what is wrong with my code.

    Thank you.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Can't access clicked method of a button from the class of a extension form

    Hi Satyaprajna,

    Did you try clicking on the button from the form to check if this code gets executed?

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Can't access clicked method of a button from the class of a extension form

    Just by looking at the code, I don't see any reason why it would not call the clicked() method of the button when ItemIdSAT field is modified.

    If it doesn't work, and since the code is anyway not ideal, then maybe it's also the quickest solution to move the code to a separate class :)

  • Satyaprajna Das Profile Picture
    22 on at
    RE: Can't access clicked method of a button from the class of a extension form

    Hello Nikolaos,

    Sorry for not using rich text formatting. I will attach the code again.

    we are upgrading the code from ax 2012 to D365. So all these codes are in same place as of ax 2012, which were working correctly in ax 2012. i am working on a heavily customized environment. So i think it will be very time consuming for me to go and move the codes to new classes everywhere. Is there any restriction of calling a control level method from a element level method in D365? Or is the coding wrong? It will be very helpful for me if i know the real reason why it's not working as i have already come across this kind of issue twice.

    event handler class of WHSPack form extension->
    class WHSPack_FormSAT_Eventhandler
    {
     	[FormControlEventHandler(formControlStr(WHSPack, ItemIdSAT), FormControlEventType::Modified)]
        	public static void ItemIdSAT_OnModified(FormControl sender, FormControlEventArgs e)
        	{	
            	FormRun fr = sender.formRun();
    		FormButtonControl ButtonPack = fr.design().controlName(formControlStr(WHSPack, ButtonPackSAT)) as FormButtonControl;
    		if(condition)
    		{
    			ButtonPack.clicked();
    		}
        	}
    }
    
    button's class _->
    
    [ExtensionOf(formControlStr(WHSPack, ButtonPackSAT))]
    final class WHSPack_ButtonPackSAT_FormSAT_Extension
    {
        	void clicked()
        	{
    		if(condition)
    		{
    			code to execute is written here
    		}
    		next clicked();
    
    	}
    }
    
    
    
    

    Thank you in advance.

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Can't access clicked method of a button from the class of a extension form

    Could you please click "Use rich text formatting" -> "insert" -> Code" when sharing your code, so that it's easier to read. Thanks!

    Anyway, I suggest moving your code away from the clicked method, into a separate class. Then you can call it from the clicked method (or even better, a MenuItem) but also from anywhere else.

    I don't think it's a good idea to call clicked method from code.

  • Satyaprajna Das Profile Picture
    22 on at
    RE: Can't access clicked method of a button from the class of a extension form

    Hello Nikolaos,

    Thanks for your quick response. In this case, if certain conditions are met, we want to execute the code inside the clicked method of the button. Same goes for the modified method as well.

    Below are my code -

    event handler class of WHSPack form extension->

    class WHSPack_FormSAT_Eventhandler

    {

    [FormControlEventHandler(formControlStr(WHSPack, ItemIdSAT), FormControlEventType::Modified)]

        public static void ItemIdSAT_OnModified(FormControl sender, FormControlEventArgs e)

        {

            FormRun fr = sender.formRun();

    FormButtonControl ButtonPack = fr.design().controlName(formControlStr(WHSPack, ButtonPackSAT)) as FormButtonControl;

    if(condition)

    {

    ButtonPack.clicked();

    }

        }

    }

    button's class _->

    [ExtensionOf(formControlStr(WHSPack, ButtonPackSAT))]

    final class WHSPack_ButtonPackSAT_FormSAT_Extension

    {

        void clicked()

        {

    if(condition)

    {

    code to execute is written here

    }

    next clicked();

    }

    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Can't access clicked method of a button from the class of a extension form

    Could you please share your code? As a rule of thumb, if you have issues with your code, you can share it right away to get faster and better help from the community.

    You say that you are trying to call clicked method. Normally you would not call clicked method, instead it's called automatically when the user clicks a button. Same applies to modified method.

    If you mean that you would like to extend the clicked method of the button with Chain of Command, you should create an extension class for this form control. The form extension class can't be used for that.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 374 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 299

#3
Saalim Ansari Profile Picture

Saalim Ansari 211

Overall leaderboard

Product updates

Dynamics 365 release plans