From a button, how to add a row, then push button in newly added row?

Simple use case:
I have a table with a button column.
A button is used to add a row to the table.
How do I then push the button in the row all in one action?

ie.
List( AddRow(Table, Column, Value), RunActions(newRow.Button) )

Also thought to try:
RunActions( AddRow(Table, Column, Value).Button )

Thanks!

This will require a helper table to save the created row into. You cannot chain button clicking to AddRow, but you can pass AddRow result (created row) to save into a cell, then reference that row:

RunActions(
  [Helper table].ModifyRows(
    [Saved row], Table.AddRow(Column, Value)
  ),
  [Helper table].[Saved row].Button
)

P.S. If it’s not a canvas button but a button in a table, then instead of creating a helper table you can just create a column for the created row in the same table where the button that you click is.

3 Likes

source

Very helpful. Thank you!

1 Like

@Paul_Danyliuk I have the same need as the original poster. Has anything changed in 3 years?

The original solution while working is a bit cumbersome:

  • If you have multiple users of the same page, they may stomp on each other.
  • You also need to clean up afterwards and clear the helper table.

I can imagine another possible hack that may be a bit cleaner

  1. Generate a random generated ID
  2. Create row with ID = generated ID
  3. Run Table.Filter(ID=Generated ID).Button

Nothing changed really; I’m doing this in an even more cumbersome way nowadays :sweat_smile:

Users won’t stomp if you add another dimension to that table, the CurrentUser, and filter by that. So instead of modifying one row, you’ll be adding rows and then cleaning them up.

Random generated ID is an interesting idea. But at that point it’s just easier to add the CreatedBy() and CreatedAt() columns and just filter for the last one with the current user.

2 Likes