Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to disable sales t...
Finance forum
Answered

How to disable sales table button in action pane in D365FO

Posted on by 630

Hi friends,

In sales table form in action pane i created new button i want to disable the button.
Please tell me how to disable the button.

Note: I want when we click on new created button it will be disable automatically.  

Thanks & Regards,

Rahul.

  • Rahul.p Profile Picture
    Rahul.p 630 on at
    RE: How to disable sales table button in action pane in D365FO

    Thanks Nikolaos, Working.

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: How to disable sales table button in action pane in D365FO

    Hi Rahul.p,


    Here's an example about how to add new button to existing form in new Dynamics AX and disable or enable it based on condition.
    https://meritsolutions.com/disable-enable-button-dynamics-ax/

    Create_2D00_button_2D00_Dynamics_2D00_AX_2D00_940x460_2D00_1.png

    I hope it will help you.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to disable sales table button in action pane in D365FO

    You should put this code in the onActivated method of SalesTable data source. Then it will check the condition every time a new SalesTable record is selected, and updates the "enabled" accordingly.

    If it's in CreateInvoice_OnClicked it's only executed when somebody clicks that button.

            FormRun formRun                = sender.formRun();
            FormDesign formDesign = formRun.design();
    	FormButtonControl Z_CreateInvoice = formDesign.controlname(formControlStrSalesTable, Z_CreateInvoice as FormButtonControl;
            SalesTable salesTable = formRun.dataSource(0).cursor() as SalesTable;
    
    
            Z_CreateInvoice.enabled(salesTable.SalesStatus == SalesStatus::Invoiced);
  • Rahul.p Profile Picture
    Rahul.p 630 on at
    RE: How to disable sales table button in action pane in D365FO

    Please check my event handler.

        [FormControlEventHandler(formControlStr(SalesTable, Z_CreateInvoice), FormControlEventType::Clicked)]
        public static void Z_CreateInvoice_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            FormRun          formrun                = sender.formRun();
            FormDesign formDesign = formrun.design();
            SalesTable salesTable = sender.formRun().dataSource(0).cursor() as SalesTable;
    
            if(salesTable.SalesStatus == SalesStatus::Invoiced)
            {
                Z_CreateInvoice.enable(true);
            }
        }

    I want if salessataus is invoiced then button should be disable.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to disable sales table button in action pane in D365FO

    It depends of your code.

    If you have an event handler you can get it like this (if it's not a string you can't use FormStringControl, instead the correct control type):

    FormDesign formDesign = formRun.design(); // You can get FormRun from the event handler parameters
    
    FormStringControl MyField = formDesign.controlName(formControlStr(SalesTable, MyField)) as FormStringControl;
    
    MyField.enabled(false);

    If you still have issues please share your code. We need to see if it's an event handler, CoC or something else.

  • Rahul.p Profile Picture
    Rahul.p 630 on at
    RE: How to disable sales table button in action pane in D365FO

    I set button AutoDeclaration property to true

    I wrote code like MyButton.enabled(true);

    But error is coming "Variable 'MyButton' is not found in scope."

    Please tell me how to declare it.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to disable sales table button in action pane in D365FO

    Seems you ended up in the Dynamics AX forum. I have moved your post to D365FO forum.

    You have some options.

    1) Set property Enabled to false in the button properties. This is only feasible if you don't have any additional requirements (we don't know since no additional details were shared).

    2) Set your button's AutoDeclaration property to true, and then in x++ code call MyButton.enabled(false) whenever you want to disable the button, or MyButton.enabled(true) when you want to enable it.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans