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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to Disable a Menu item button ?

(0) ShareShare
ReportReport
Posted on by 70

Hello Guys,

I want to disable a menu item button under conditions, I did my work on the eventHandler "OnClicked" but the order is coming after we click and finish the process. I want to prevent the user from continuing the confirm button process several condition, so I moved my code to the Activated Event Handler on the form 

but no class is working for the button neither the FormControl , FormButtonControl or the FormMenuButtonControl and FormFunctionButtonControl

the function I'm using is sender.FormRun().design(0).ControlName("MENUITEMNAME").enabled(false); 

even i tried to remove the (0) from the design but all is the same, nothing is working, 

the error i'm receiving in the system is"Unable to cast object from type 'FormControl.buttonConfirm' to type 'Dynamics.AX.Application.FormButtonControl'  or any type i chose other than FormControl
and on the FormControl class also don't work.

4341.Untitled.png_2D00_640x480.png

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,107 Most Valuable Professional on at

    Hi AklG,

    So you want to control the Confirm button based on some conditions. Writing on the Activated Event Handler on the form is fine. But do not forget that, the Confirm button is already controlled by the PurchStatus and DocumentState field.

        /// 
        ///
        /// 
        /// 
        /// 
        [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::Activated)]
        public static void PurchTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
            PurchTable                  purchTable                = sender.cursor();
            FormDataSource              purchTable_ds             = sender.formRun().dataSource("PurchTable");
            PurchLine                   purchLine;
            AccountingDistribution      AccountingDistribution;
            FormControl                 FC                        = sender.formRun().design(0).controlName("buttonConfirm");
    
            if(some condition)
            {
                FC.enabled(false);
            }
            
        }

  • Alex VN Profile Picture
    1,994 on at

    Hi,

    In this case, can you try to call the same code twice for sender.formRun().design()? This mean you will not use the FC variable to get the button.

    Please check and let us know the result to validate further.

  • AklG Profile Picture
    70 on at

    Hi Komi Siabi

    it did not worked, after doing this still the confirm button opened , i tried to test it and put the FC .enabled(false); in the event handler without conditions but still opened

  • AklG Profile Picture
    70 on at

    hi Alex VN,

    i didn't get you, how am supposed to do it?

  • Alex VN Profile Picture
    1,994 on at

    Hi,

    You can remove your FC variable and every place instead of calling FC.Enabled(false); you can use:

    sender.FormRun().design(0).ControlName("MENUITEMNAME").enabled(false);

  • AklG Profile Picture
    70 on at

    ah okay, i tried this before and also don't get any result.

    i will try to apply my code on the UpdateDesign method on the level of the form

  • Suggested answer
    Alex VN Profile Picture
    1,994 on at

    Ah ha,

    Then I think got the issue.

    You can see on PurchTable we have method: enableJournalButtons() to enable or disable the confirm button.

    As buttonConfirm is auto declared so you can just extend enableJournalButtons, add your logic after the next call and call buttonConfirm.enabled(false);

    The above issue is because you call on activated but later enableJournalButtons() is standardly called and enable the button again.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans