PadCodedocs

Reusable actions

Name a list of steps once, in Data & Logic, and run it from any view with Run Action.

A reusable action is a list of steps with a name. You keep it in Data & Logic, and any view runs it with the Run Action step. A Sign in button and the password field's Return key can share the same sign-in steps, and when you change them, both get the change.

Data & Logic's reusable actions: each one's name, a short outline of its steps, and Edit steps.

#Make one

  1. In the Library (the left panel), open Data & Logic (the last tab, or ⌘5).
  2. Under Reusable actions, tap New action. A new, empty action named newAction opens.
  3. Tap Add action to add steps. They work the same as in a view's Actions tab: tap a step to open it, touch and hold it to move or remove it. See How steps run.
  4. Tap Done.

The top of the sheet reminds you: "Runs these steps in order wherever “Run Action → newAction” is used."

A reusable action named sendInvoice, open: two If steps and a Try, then Add action.

#Rename, edit or delete one

Each reusable action has a card under Reusable actions, with its steps in short, like "Set Value · Try · Set Value".

  • Rename: tap its name and type a new one. Every Run Action that runs it follows the new name. A name keeps only letters, numbers and _, and it can't be empty or the same as another action's.
  • Edit: tap Edit steps (Add steps while it has none).
  • Delete: tap its trash button. It's deleted right away; Undo (⌘Z) brings it back.

#Run one from a view

  1. Select the view and open the Inspector's Actions tab.
  2. Pick the When, then tap Add action and choose Run Action (under Logic).
  3. Open the step and pick the reusable action in Action.
A Sign in button whose only step is Run Action, running signIn.

The button next to Action (Edit or create a reusable action) has two shortcuts:

  • Edit “signIn” opens the picked action's steps.
  • New Reusable Action makes a new action, picks it in this step and opens it, so you can add its steps right away.

Run Action works anywhere a step can go: inside an If, a Try, a Show Alert button, or another reusable action.

#Pass values in

Run Action's With sends values to the action, like which note to delete.

  1. In the Run Action step, under With, tap Add field.
  2. Name the field, like noteID, and give it a value. Use ⚡︎ to link it to app data or a formula.
  3. In the reusable action's steps, read the value as params.noteID, like Where: it.id == params.noteID in a Remove from List.

#How it runs

The action's steps run right where its Run Action is, as part of the same run, with the same rules: in order, one at a time, each slow step waited for. When they finish, the steps after Run Action carry on.

  • A step that fails inside the action stops the whole run, unless something is catching it. Put the Run Action, or the steps inside the action, in a Try.
  • Stop inside the action ends the whole run, not only the action.
  • In Preview's debugger, the action's steps show under its Run Action, indented.
  • On the Flow board, the action's own steps aren't drawn. What they did in the last run counts for the Run Action step.

#See also