How to perform multiple actions with a single button (or, how to use RunActions()!)

With a basic button, you’re able to modify a single table or perform a single type of action (for example, press multiple buttons). If you want a single button to perform actions on multiple tables or execute varying types of actions, RunActions() is a great thing to know about!

Here’s a help article I wrote on the topic: https://help.coda.io/en/articles/3925472-perform-multiple-actions-with-a-single-button

Let me know if there are any other interesting ways you like to use RunActions()!

5 Likes

Interestingly, I just helped someone else with a very similar task. Here’s the quick example:

5 Likes

Ooh, there’s so much more to that!

  • If/Switch/SwitchIf work within actions:

    If(
      thisRow.Done,
      SomeTable.AddRow(...),
      OtherTable.Filter(...).DeleteRows()
    )
    

    Use _Noop() (no operation) if you only need to do something if the condition is true but nothing if it’s false:

    If(
      thisRow.Done,
      thisRow.DeleteRows(),
      _Noop()
    )
    
  • FormulaMap() works within actions:

    Projects.Filter(...).FormulaMap(RunActions(
      thisRow.ModifyRows([_Current project], CurrentValue),
      Tasks.Filter(Project = thisRow.[_Current project]).ModifyRows(...)
    ))
    
    Sequence(1, 10).FormulaMap(
      Table.AddRow(Index, CurrentValue)
    )
    
  • Of course you can combine everything into one huge action, like here:
    Complex Coda Docs — Mapping them out for sustainability and continuous development

  • Buttons can press each other to make loops.

  • Buttons are great replacements for checkboxes where you need them checked/unchecked differently per user — see how starring/unstarring items works in @BenLee’s example here.


Also a thing to know: wrapping your action with RunActions is not necessary when you’re only performing one instruction (one action or one set of buttons to press). I.e. there’s no need to write

RunActions(
  Tasks.[Toggle Done]
)

to press all buttons in a column of Tasks. Simply

Tasks.[Toggle Done]

would work just as well. You only need RunActions() when you’re declaring two or more actions in a sequence explicitly (i.e. with a comma between).

6 Likes

Hi, Paul. My name is Breno.
Why would you use function _noop() that is not supported , if you could use switchif() instead of if()?
Is it any different?

IIRC Coda won’t let you use SwitchIf() in an action without an “else” branch. You’ll still have to use _Noop().

It is not unsupported — in fact Coda uses it a lot (e.g. for disabled buttons), and it will insert it into a button action that you haven’t finished setting up (that’s how I learnt about it).

1 Like

Hello, I have 2 documents. One my team uses operationally i.e. fills in data into rows and when finished they click a button which copies all the values from that row into a separate document. This works well. I tried using RunActions to keep doing this copy row to another doc task but can’t figure out how to also have it delete the row that the staff pushed on their operational document. Preferably, it would only delete the row after successfully doing the first action, which works well.

Any help would be greatly appreciated.

I have this setup:

And the following formula works:
image

This is within one document, the tables can sit on different pages. I am pretty sure the delete doesn’t happen if the first part of the function fails.

I am wondering how you move the rows to a different document though, because that might make it a bit different.

1 Like

Thank you for the help and the process is working as needed.