[Public Beta] Database change triggers

I just read this and we might be missing an opportunity to format the text for better readability. Here’s one attempt to rewrite it:

Trigger Event

This event is defined in the Backend Workflow section and runs workflows triggered by changes in the database.

Whenever an item of the given type is modified, we check the “Only when…” condition of the event, and if the condition passes, we run the workflow.

Use cases

This is useful for situations where a given piece of data could be modified by many different places in your application, and you want to make sure something happens each time the data is modified in a specific way. For instance, you could use this to sync the value of certain data types to an external API whenever the data is modified.

Trigger events are kicked off by any change to the data, regardless if the change is initiated by:

  • a workflow,
  • an API call, or
  • manually editing the data in the editor.

When working with database trigger events, there are two special data types:

  • Thing Before Change”: represents the data of the thing that was changed prior to the changes being made
  • Thing Now”: the current data

where “Thing” will change to match the type of thing you are working with

If a workflow modifies a thing multiple times, we only fire triggers once: “Thing Before Change” will be the data at the beginning of the workflow, and “New Thing” will be the data at the end.

Triggers are also fired when a thing is created or deleted.

If it was created, “Thing Before Change is empty” will be true, and if it was deleted “Thing Now is empty” will be true.

Caveats :warning:

There are several caveats about using data triggers.

  1. Although you can use “Current User” to see which user, if any, initiated the workflow that changed the thing, trigger workflows run with full administrative privileges and privacy roles are not applied while the trigger is running,
    Any searches performed during the workflow will return all results, not just the results the current user is allowed to see.

  2. Triggers cannot kick off other triggers: if data is modified by a workflow initiated by a trigger, we do not check to see if those modifications are eligible for initiating other trigger events.

  3. The “Only when…” condition can only use “Thing Now” and “Thing Before Change” instead of the full list of Bubble data sources. The full list of data sources are available in the actions kicked off by the trigger.

Finally, keep in mind that workflows kicked off by triggers consume capacity, like any other Bubble workflow. If your application kicks off multiple trigger workflows every time data is modified, this can add up to a lot of overhead to the total capacity used by your application. To control this, use strict “Only when…” conditions to make sure you are only running trigger workflows when you need to.

5 Likes