Skip to main content
Dynamics 365 Community / Forums / Finance forum / Setting a button's...
Finance forum
Suggested answer

Setting a button's text and visibility in a grid based on conditions

editSubscribe (0) ShareShare
ReportReport
Posted on by 15

Hello,

I'm trying to put a column on a form grid that acts like a button (either it is a button, or is clickable text), where the buttoncontrol.text() and the buttoncontrol.visible() will change according to certain conditions. For example: in Row 1 condition A is true, button.visible = false and button.text = 'empty string'. In Row 2 condition A is false, set button.visible = true and button.text = 'true'.

The data source on the form/grid is a View generated from a query. "Condition A" is a computed column on the view, ie "if Condition A, set button text = 'lorem ipsum' and visible = true".

pastedimage1666196043908v2.png

How would you go about doing something like this? Is it possible to create a method call/override in the form to loop through the rows/buttons and check conditions per row, then set visible/text on a button, per row? 

It needs to be clickable because clicking the enabled/visible button takes args from the row and links to another form based on those args. I have that bit working but I can't for the life of me figure out how to set text on a button per row, based on args from that row. 

This is on a net new/custom form, view, and query.

  • GirishS Profile Picture
    GirishS 27,799 Super User on at
    RE: Setting a button's text and visibility in a grid based on conditions

    What about edit method?  

    Refer to the below URL for edit method. Check whether edit method can suit your scenario.

    https://dynamics365musings.com/d365-edit-method/

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    Martin Dráb 222,562 Super User on at
    RE: Setting a button's text and visibility in a grid based on conditions

    You can't set visibility on individual cells in a grid. You can only hide the whole column, which clearly isn't what you want. But you can use empty values in those cells.

    Regarding the button, why you can't you follow F&O form patterns and place the button in a toolbar above the grid? Please check out Toolbar and List subpattern.

  • RE: Setting a button's text and visibility in a grid based on conditions

    If you are adding a view as datasource to a form you don't have access to CRUD operations.

    I don't want to CUD, but I do wish to Read - ie Read the value of a field in a record and set the text of a form control. Is that not possible?

    My suggestion will be creating a display method on the form instead of controls

    I have a display method, as shown in the screenshot above. The 'Coll Status' column is a display method. However, I don't think it's possible to make that display method a clickable button, which is what I'm trying to accomplish. Either make the display method clickable, or find out how to make a clickable button update according to the applicable record. 

    Also display method will view only data you cannot edit it.

    i don't want to edit the data, only Read the data and set the button.text() based on the Read data. 

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,799 Super User on at
    RE: Setting a button's text and visibility in a grid based on conditions

    If you are adding a view as datasource to a form you don't have access to CRUD operations.

    My suggestion will be creating a display method on the form instead of controls.

    Also display method will view only data you cannot edit it.

    Thanks,

    Girish S.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 282,978 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans