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

Announcements

No record found.

News and Announcements icon
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 1,038

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!

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    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.

  • Suggested answer
    Momochi Profile Picture
    1,038 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 663

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 439 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 337 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans