Skip to main content

Notifications

Announcements

No record found.

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 508
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 230,371 Most Valuable Professional 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 508 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 230,371 Most Valuable Professional 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).

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans