Experience Level
This core reference entry is suited for advanced-level builders.
In-depth articles (13):
In-depth articles (13):
To learn about this topic more in-depth, we recommend reading the suggested articles below:
Database trigger events
Article: Database trigger events
Article: Client-side and server-side Client-side means that a workflow is executed in whole on the Bubble server. Client-side means that the workflow may include part, such as the event, on the user's device.
Workload
To understand how the workload metrics works, and how you can optimize for it, you may find the following articles useful:
Article series: Pricing and workload
Article series: Optimizing for workload
Logic
Workflows is a part of the Logic series in the user manual.
Article series: Logic
Article: The frontend and backend
Article: Dynamic expressions Dynamic expressions are used both to set up conditions, and are highly useful in different actions that you may want to add to your workflows.
Article: Conditions Conditions are used to determine whether a workflow or action should run or not, by checking whether something is true.
Article series: Workflows
Article series: Navigation Using workflows to let the user navigate between pages and page sections.
Debugging
All apps have the occasional bug, and our debugging tools help you squish them efficiently. The debugger helps you go through workflows step by step to see how they perform and the values they return.
Article series: Debugging your application
Videos (2):
Videos (2):
Bubble Academy: The Workflow Tab: Bubble Introduction Series [4/10]
Bubble Academy: Understanding Workflow Execution Rules
The database trigger event triggers whenever specific data is changes in the database. It is defined in the backend workflow editor.
Whenever a database thing of the specified type is modified, Bubble checks the "Only when..." condition of the event. If the condition returns a yes, the workflow runs.
You first set the Type of data on the event. This instructs Bubble what data type to watch.
Then, use the Only when... field to set a condition for what kind of changes should trigger the event
Database trigger events are kicked off by any change to the data, regardless if the change is initiated by a workflow, an API call, or from manually editing the data in the editor.
Thing before change and thing now
When working with database trigger events, two unique data sources become available:
Thing before change
Thing now
"Thing" will change to match the type of thing you are working with. You can reference these two data sources in the condition on the event itself, and in any actions within the database trigger event workflow.
If a thing is created or deleted
Created
If a thing is created, its thing before change
data source will return an empty value, since there is no former thing to refer to. To check whether a thing was created, you can use the condition Thing before change is empty
.
Deleted
If a thing is deleted, its thing now
data source will return an empty value, since the change made to the thing was to remove it altogether. To check whether a thing was deleted, you can use the condition Thing now is empty
.
Precautions
There are a few caveats and precautions you should be aware of when using trigger events.
Multiple changes in one workflow
If a workflow modifies a thing multiple times, database trigger events will only triggers once:
Thing before change will reflect the data in the thing before any changes were made, and Thing now will reflect the data in the thing after the last change has happened.
Privacy rules
The following guidelines are important to note regarding privacy rules:
You can refer the Current user in an action in the database trigger event workflow
Unlike other workflows, database trigger events run with full administrative privileges
This means privacy rules are not applied to any actions and expressions within that workflow
Searches performed within the workflow will return all results, not just the results the current user is allowed to see
Triggers cannot kick of other triggers
A database event trigger cannot kick off a second triggers:
If data is modified by a workflow initiated by a trigger, Bubble does not check to see if those modifications are eligible for initiating other trigger events.
You can get around this by scheduling a separate custom event or API workflow from the original database trigger event workflow. Any database change made by this second workflow will trigger as expected.
This method will consume more workload
Also, while sometimes necessary, it should be used with caution, since it can easily set up a cascade or loop of workflows that can spend significant resources and possible lead to data corruption
Data source availability
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.
A note on workload: keep in mind that workflows kicked off by triggers consume server 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. Article series: Pricing and workload
Note: If you have more than 20 database triggers that kick off at once, the remaining triggers will be scheduled to protect your app's infrastructure from consuming too much memory.
Event name
Enter the name of the workflow.
Type of thing
A database trigger event watches a certain type of thing for changes. Define the type here.
Timezone selection
Override the backend trigger's timezone by setting an alternative timezone with a static or dynamic choice. For this setting to be available you must first enable the setting Enable timezone override controls in your app's general settings.