Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / How to make button in ...
Finance forum
Answered

How to make button in Action Pane disabled based on row state of a grid ?

Posted on by 390
Hi,
 
In a custom form which has a grid contain a table, how to make the button on top of it to be enabled or disabled based on the record highlighted on the grid ?
So for example, if it is SalesTable, the button Delete is disabled when Sales status is invoiced, but will be enable if it is not invoiced yet.
 
And where to put the code ? Is it on the datasource's method and may I know which method I should overwrite ? I tried to look at the SalesTable for example, but my knowledge is limited on this. 
Can I ask for a guide ?
 
Thanks,
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    How to make button in Action Pane disabled based on row state of a grid ?
    The problem is that you're trying to negate the value of the Status field. I think you meant this:
    public int active()
    {
        int ret = super();
    
        FormButtonGroupControlPost.enabled(test_Table.Status != TEST_Status::Posted);
    
        return ret;
    }
  • Ken Manhattan Profile Picture
    Ken Manhattan 390 on at
    How to make button in Action Pane disabled based on row state of a grid ?
    Hi Martin,
     
    Yes, noted about the AllowEdit, but actually it is only for my example here. My case here unfortunately is just a button which I want to disable when it is not satisfied my record status highlighted on grid.
     
    I tried to follow your clue, though. but maybe it is was not in the right syntax :
    public int active()
            {
                int ret;
            
                ret = super();
    
                FormButtonGroupControlPost.enabled(!TEST_Table.Status==TEST_status::Posted);
            
                return ret;
            }
    
    This is an overwrite method "Active" of the form's datasource. So, I expected the button is enable when my record status is not Posted.
     
    Getting this error now:
    Error        Operator '==' cannot be applied to operands of type 'boolean' and 'Extensible Enumeration(MyStatus)'. "
     
    The field Status is with EDT enum TEST_status
     
    May I know the correct syntax ?
     
    Thanks
     
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    How to make button in Action Pane disabled based on row state of a grid ?
    When you select a row in grid, active() method of the form data source gets called, therefore that's the place for your logic.
     
    When you want to disable deleting, you shouldn't focus on a button, because users could use a keyboard shortcut or so. You should change properties of the data source (allowDelete(false)) instead.
     
    Also, don't forget that there already may be other code for the same purpose. That would be the case of SalesTable form. If you overwrite the value set by the existing code, you'd break several standard features (and may end up with wrong data).

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,115 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,971 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans