Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Enable/Disable Menu Item Button on a Form

(0) ShareShare
ReportReport
Posted on by 981

Hello awesome community!

I'm still very new to D365, and I'm working on my first report so please help the newbie! public static void SalesTable_Pre_run(XppPrePostArgs args) { FormRun sender = args.getThis(); FormDataSource fds = sender.dataSource(1); SalesTable _salesTable = fds.cursor(); if(_salesTable.DocumentStatus == DocumentStatus::Confirmation) sender.control(sender.controlId(formControlStr(SalesTable, MyMenuItemName))).enabled(true); else sender.control(sender.controlId(formControlStr(SalesTable, MyMenuItemName))).enabled(false); } }

After I did the build, when I go to the All Sales Order screen and choose one of the sales order, the screen freezes and times out.

Please can anyone tell me what I'm missing or doing wrong?

Thanks in advance!

  • Suggested answer
    Momochi Profile Picture
    981 on at
    RE: Enable/Disable Menu Item Button on a Form

    Thank you Mr. Nikolaos for your help!

    I did as what you pointed out to me is to go with the OnActivated Method of the data source on the form.

    and here is the new code that worked for me:

    class SalesTableEventHandler
    {
        [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]
        public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
            SalesTable          _salesTable     = sender.cursor(); //selected record
            FormDataSource      salesTable_ds   = sender.formRun().dataSource("SalesTable"); //DataSource
            FormRun             element       = sender.formRun(); //form element
            FormControl         myNewButton   = element.design(0).controlName("MyMenuItemName");
            //button on the form
            if(_salesTable.DocumentStatus == DocumentStatus::Confirmation)
                myNewButton.enabled(true);
            else
                myNewButton.enabled(false);
        }
    
    }

    Thanks again

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Enable/Disable Menu Item Button on a Form

    I don't think that your code (that you shared with us) causes the freezing. You can debug it and see for yourself.

    Anyway if you want to enable/disable controls based on some data in the table, you need to hook in the active method of the data source. Run method of the form is executed when the form is opened. But you want your code to run every time when a new order is selected.

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 372 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 291

#3
Saalim Ansari Profile Picture

Saalim Ansari 209

Overall leaderboard

Product updates

Dynamics 365 release plans