How to use Database triggers in Bubble
Automate some backend data changes, so magic happens, like, magically.
Let’s automate some stuff. Magic stuff.
I’m talking about the cool feature that Bubble has, where some data can change automagically, when some other data changes.
What possible reason could we have to make some data change by itself? I mean that sounds bad doesn’t it? Well, there are times when we want to create new data, based on that data we have. Let’s think about Customers.
We might have a Field called First, and a field called Last. We ask for these things during a sign up process, and the customer has typed these things in.
If a customer just typed in John, and Smith, it would seem weird for them to also type in ‘John Smith’ in some ‘Full Name’ field. We might want to use a ‘Full Name’ value though perhaps elsewhere in the app, such as on an Account Settings page. We can construct this field automatically based on the First and Last fields.
More importantly, if the customer updates their Last name in the future, we don’t want to have to ask them their Full Name again.. we can update it for them, via a Database Trigger.
For this magic trick, you’ll need to use Backend Workflows, and for that you’ll need to be on a paid Bubble plan.
To create one, Click General | New database trigger event
Configure it like this
Only when: User Before Change’s First is not User Now’s First or User Before Change’s Last is not User Now’s Last
The condition sets us up so that a change of either the First or Last names will trigger the Action.
The Action we’ll add, is to update the ‘First Last’ field, to match the new values .. meaning the values they are ‘Now’ rather than the values they were ‘Before the change’
Thing to change: User Now
First Last = User Now’s First User Now’s Last
and that’s it :) you have now automated one data field, based on changes in 2 other data fields, making your life easier, and your data more consistent.
Some other use cases I have set up using Database Triggers:
Emailing myself when key onboarding events happen for new customers
Updating numerical values when text values are selected in dropdowns
Adding data/time information to work items when that are marked completed
Thanks for reading this free article. Many of my articles are freely available, but some are for paid subscribers only. Subscribe below if you want access to all content.