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, ...
Answered

Enable/Disable Menu Item Button on a Form

(0) ShareShare
ReportReport
Posted on by 1,036

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,160 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,036 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

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans