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()!

4 Likes

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

4 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).

3 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).