Skip to main content

Notifications

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

  • Suggested answer
    Alex VN Profile Picture
    1,994 on at
    RE: How to Disable a Menu item button ?

    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.

  • AklG Profile Picture
    70 on at
    RE: How to Disable a Menu item button ?

    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

  • Alex VN Profile Picture
    1,994 on at
    RE: How to Disable a Menu item button ?

    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
    RE: How to Disable a Menu item button ?

    hi Alex VN,

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

  • AklG Profile Picture
    70 on at
    RE: How to Disable a Menu item button ?

    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

  • Alex VN Profile Picture
    1,994 on at
    RE: How to Disable a Menu item button ?

    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.

  • Suggested answer
    Komi Siabi Profile Picture
    12,837 Most Valuable Professional on at
    RE: How to Disable a Menu item button ?

    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);
            }
            
        }

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 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,978 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans