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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

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

(0) ShareShare
ReportReport
Posted on by 558
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,
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    240,534 Most Valuable Professional on at
    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).
  • Ken Manhattan Profile Picture
    558 on at
    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
     
     
  • Verified answer
    Martin Dráb Profile Picture
    240,534 Most Valuable Professional on at
    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;
    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 341 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 312

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 262 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans