Bulk operations
This section covers the bulk operations, which lets you run API workflows on a list of things directly from the Bubble database editor
This article focuses on performing bulk operations by using the bulk operation feature in the Bubble database editor. If you're looking for ways to perform bulk operations in your app, we have links to relevant methods at the bottom of the article.
What are bulk operations?
In the context of the Bubble database, bulk operations are any kind of process that you apply to multiple things simultaneously or sequentially. While the Make changes to a list of things action is technically a bulk operation, we generally mean working on longer lists (100+ things) and sometimes more advanced processing.
Bulk operations can mean doing stuff like:
Making changes to specific fields in a list of things
Deleting a long list of things
Creating a list of new things
The bulk operation feature
Note on emails: the bulk operation feature cannot be used to mass send emails.
Note: Bulk operations are performed server-side, but the bulk operations feature relies on client-side actions that depend on your browser window staying open and active.
In other words, you need to keep the popup open for them to continue until the process is done.
The bulk operation feature is an in-editor operation that you can run directly from the database editor. Technically, this does the same as scheduling an API workflow, where you select an API workflow to run, and it will process the currently viewed list of things, or the things you have selected.
The bulk feature only supports one parameter: the list of things you want to make changes to
You don't need to add any events in your app (such as a button click) – it can be executed from the Bubble editor
Since this is an extension of the Schedule API workflow on a list function, the processing will be done in parallell, as opposed to in sequence
Using the bulk operations feature
Building the API workflow
Before you can perform bulk workflows on your data, you need to build the API workflows that you are going to call.
If you are not familiar with Bubble's Workflow API and how to set up API workflows, we recommend you first get to know how they work. The first link below gives an introductory guide to the Workflow API in general, and the second shows you how to set up API workflows that can be used with bulk operations.
Article: The Workflow API Article API Workflows
Valid bulk operations feature parameters
To be valid for scheduling by the Bulk operation feature, API workflows must have a few properties in place:
A thing parameter: the workflow must include a parameter that requires a 'thing' of the same data type as the one you intend to perform the bulk operation on:
Only set up one parameter: when a bulk operation is called, Bubble will only fill one parameter: the thing it's currently scheduling the operation on. In other words, do not set up any other parameters.
The thing cannot be a list: bulk operations are scheduled one-by-one on a list of things. In other words, the parameter that asks for which thing to perform the operation on should ask for a single think, not a list/array.
It does not need to be exposed as a public API Workflow: while it will still work if you expose it, it's better to uncheck the checkbox to make sure that it cannot be triggered from outside of your app.
Adding actions to the API workflow
Now we have an API Workflow that accepts a single parameter: the thing that we want to run the operation on. In our example we set that thing to a custom data type called Product, so let's make a change to that thing. We have a on the product called Published that we want to set to yes.
In our API Workflow, this is a very simple operation:
First, we add the Make changes to a thing action to the API Workflow
Then, we choose product as the thing we want to change. This is the parameter we set up earlier.
Finally, we set the Published field on the product to yes
Running the bulk operation feature
Now that we have the workflow we want to run the bulk operation on, let's see how we trigger it to run.
First, we select the data type that we want to run the bulk operation feature on. In this case, we want to work with Products
Next, select the Products that you want to run the bulk operation feature on. Trucker cap and Baseball cap are ready to be published, but Product 1 still needs some work, so let's just check to two top ones.
Then, we click the Bulk button, where we'll select with API Workflow to run on the selected things.
The bulk operation feature typically make changes to a list of records. If you make a mistake when running the bulk operation feature, you can restore the data type to what it looked like before the operation by using the feature.
We also recommend testing your API workflow in the before making changes to .
In the first dropdown, we choose what list to run the operation on. You can choose to run it on the entire current view, or the selected entries – in our case we specifically selected two entries, to let's go with that
In the second dropdown you will find the list of compatible API Workflows. If the Workflow does not accept the same data type as a parameter, it will not be selectable
The text next to point three confirms that the workflow will in this case be run on 2 entries, which is what we selected
Finally, we can click Run workflow and the operation will start. Since we are only making a small change on two entries, it should finish very quickly.
Looking again at the data in our database, we can see that the two data types we selected now have their Published field set to yes.
Combining the bulk operations feature with views
Views let you filter the data displayed in the database editor by specific constraints, just like the Do a search for data source. Since bulk operations feature lets you run the operation on all records in the current view, you can combine these features to flexibly run bulk operations on things that match specific criteria, instead of manually selecting the things in the list.
To set up a new view, click the New view button or the pencil icon next to the data type you want to run an operation on.
Cases
Case 1: Using the Bulk feature in the database editor to change a list of users
In the first case, we'll make a fairly simple change to a list of Users. We're going to assume that you already have a collection of users in your app, and you want to introduce roles for these users, such as admin and regular user. Furthermore, we'll assume that all registered users thus far will be regular users, meaning that we can apply the change to all users in the database.
The roles are saved in an called Roles.
What we would to do is:
Search for all users without any constraints
Specify the role we want those users to be assigned
Save that value in the Role field (option set) saved on the User data type.
This is an operation we can run directly from the Bubble database editor using the Bulk feature.
Since we want to apply it to all users, we don't need to set up any constraints. We can apply the bulk operation to all Users in the database.
We only need to send one parameter (the list of Users), and can specify the Role option set to apply to those users in the API workflow itself, since it's the same for everyone
We'll assume you have already set up the fields and option set needed. First, let's have a look at what that API workflow needs to look like:
Let's go over the two points:
We've given the API workflow a fitting name, and made sure it's not exposed publicly, since we don't want to trigger this workflow from an external system
We've set up a parameter called user, and set the type to User
Note that point two is not a list. This is because the Schedule API workflow on a list action handles items individually. In other words, one workflow runs per item in the list – it doesn't make changes to the entire list in one operation (even if the workflows are executed in parallell).
Let's check out the action that makes changes to the User:
Since all users will have the same role, we specify the value directly as a static value in the user. The data source is set to the option set Roles, and the value Regular user.
And we're done! Let's see how we would run that from the Bubble editor:
As you can see, the Role field on all Users is empty as of now. Click the Bulk button in the top-right corner to start the process. This brings up the window below:
First, we pick the workflow that we created earlier. This is listed as a valid choice for two reasons:
The API workflows has only one parameter: User.
We are currently looking at the list of Users in the database.
Then, click Run workflow.
In this example, we had only five things to change, and the operation will normally finish in less than a couple of seconds.
Case 2: Adding a discount to a list of Products from your app
Let's say that you are running an eCommerce store, and you have a list of a custom data type called Products that your customers can buy. We also have a list of You make the decision to discount products from a specific vendor by 25%, and you store that discount in a field on each product called Discount. Each Product already has a field called Price, that reflects the regular price of the product.
What we would need to do in that case, is:
Search for all Products from that Vendor
Specify a discount to add
Save that value in the Discount field on each of the Products found in step 1
We are going to use Schedule API workflow on a list to make the changes. In this example, we can't use the Bulk feature in the Bubble editor, for two reasons:
We need to search for the correct Vendor in the database (database views cannot specify a database thing as a filter)
We need to send multiple parameters (the Product to change and the discount value) (The Bulk feature only supports one parameter – the thing to change)
Instead of using the bulk feature, we'll set up a very simple form that accepts two parameters, as well as a button that starts the operation:
With that form set up, we can choose a Vendor from the database, specify a discount, and then click the button to start the Schedule API workflow on a list process. As we explored earlier, shortly after the button has been clicked (Bubble's loading bar will show), the operation starts on the Bubble server, meaning that you can close the browser tab and the operation will continue to run until it's finished. The time it takes to schedule the workflow can vary somewhat depending on the length of the list.
For the next step, we're going to set up the scheduling action when the button is pressed. Right-click the button and select Start/Edit Workflow in the dropdown menu or click ⌘ + K / Ctrl + K to create the in the .
Let's go over the screenshot point-by-point:
First, we search for the Products we want to process
We specify the Vendor selected in the dropdown as a constraint
The scheduled date we want to process the list: makes sure we run it immediately.
This field specifies what we want to make changes to. In our case, we want to make changes to each product in the list. By setting the data source as This product, we specify that the changes should be applied to the individual Product currently being processed by this specific API workflow.
Finally, we use the Input discount field's value as the data source for the discount to apply
This kind of workflow can be used both in one-off scenarios, or as a standard feature in your app. As we've seen, it's quick to set up and will reliably finish even on long lists of things.
Bulk operations in your app
If you need to set up and perform bulk operations in your app, as opposed to in the Bubble editor, there are three common methods outlined below that are used for this purpose:
Last updated