Running a function when records change

Available in self-service apps

Set up an automation or a workflow Run function step so a function runs without anyone pressing a button, and learn the loop protection and limits.

Use an automation or the workflow step Run function to run a function automatically, for example to recalculate an invoice's total when one of its lines changes. Nobody has to press a button.

Both run as the system, not as the person who made the change. Both stay within the data access the function declares. Both run only functions whose tests have passed.

Choosing between an automation and a workflow step

AutomationWorkflow step Run function
Starts whenA record of a type is created or changedThe workflow reaches that step
Set up onThe record type's Main tabThe workflow builder
TimingRuns straight away, once, within 50 secondsRuns at its place in the workflow, so it can follow waiting or approvals

An automation never waits. If you need to wait for a day, a person or a decision, use a workflow. For workflows in general, see What a workflow is and How a workflow runs.

Add an automation to a record type

  1. Open the record type and go to its Main tab.
  2. Find Automations: when records change. Add an automation. A record type can have up to five.
  3. Give it a label.
  4. Choose the function.
  5. Choose when it runs: when a record is created, when it is changed, or both.
  6. For changes, you can limit it to when certain fields changed.
  7. Optionally add a condition on the record, so the function runs only for some records.
  8. Give each of the function's inputs a value. An input can be a fixed value, a field of the record, the record's id, or today or now.
  9. Switch the automation on.

You can also ask Rad Bot. It offers an automation as part of a change to the record type.

Rules that apply to every automation

  • Who it acts as. The system. The record's history does not show the person who made the change as the actor of the automation.
  • Only tested functions. If the function has changed and its tests have not passed since, the automation does not run it. The run history says "Not run: not tested". Run the function's tests again to fix this.
  • Installed modules. On a record type that belongs to an installed module, the module's own automations stay as the module set them. With the module checked out, you can add your own beside them.

How loops are prevented

An automation that updates the record that started it could start itself again. RAD Platform stops this in several ways:

  • If the function may update the same record type, the automation must name the changed fields that start it. The function must not write those fields.
  • A chain of functions starting each other is stopped three deep.
  • One record runs at most ten automations a minute.
  • A burst of more than 300 automations due in one minute across the app pauses automations for a few minutes. Admins are told when this happens.

Runs that are skipped for any of these reasons show in the run history.

Add the Run function step to a workflow

  1. Open the workflow builder for the record type.
  2. From the Data group, add Run function.
  3. Choose the function.
  4. Give each input a value, or use the Insert value menu to take one from the record or from an earlier step.
  5. Name the step's result. Later steps use this name.

Rad Bot can add this step when it changes a workflow. It checks the function and its inputs first.

The two paths

The step has two paths:

  • Done, when the function ran.
  • Failed, when the function fails, is refused or is not tested. Nothing the function wrote is saved, and the record's history says why.

Using the result in later steps

Later steps can read these values, where calc stands for the name you gave the result:

  • {{steps.calc._ok}}: the function ran without an error.
  • {{steps.calc._error}}: the error, if there was one.
  • Each output the function declares, for example {{steps.calc.total}}.

When it does not run

  • "Not run: not tested" in the run history. The function has changed since its tests last passed. Re-run its tests.
  • An automation seems to skip runs. Check the run history for a loop limit or a paused burst.
  • A workflow takes the Failed path. Open the record's history to read the reason.

See also Custom actions, which run a function when a person presses a button, and What end users and visitors may do.