Bubble Docs
  • Introduction
  • New? Start Here
  • What is Bubble?
  • The Glossary
  • User manual
    • Getting started
      • What is Bubble?
      • Building for...
        • Web
        • Native iOS and Android
          • Mobile app quick start guide
          • What is a native mobile app?
          • Native mobile vs. web development
          • Differences in native and web elements
          • Native mobile app terminology
      • Building your first app
        • Planning features
        • Database structure
        • Design and UX
        • eCommerce and payments
          • Shopping cart
          • Checkout page
          • One-time payments
          • Subscriptions
          • Marketplace
      • Creating and managing apps
      • The Bubble editor
        • Tabs and sections
          • Design tab
            • The element tree
            • The property editor
          • Workflow tab
          • Data tab
          • Styles tab
          • Plugins tab
          • Settings tab
            • Application settings
              • Custom headers/body
              • Visual settings
              • Social media sharing
              • Translating your app
              • Email settings
              • Collaboration
            • Custom domain and DNS
          • Logs tab
        • Tools
          • Key features
          • The search tool
          • The Issue Checker
          • The element tree
          • The element property editor
          • The debugger
          • Notes
        • Previewing your app
      • Transitioning to Bubble from...
        • JavaScript
        • HTML and CSS
        • SQL
    • Design
      • Elements
        • Web app
          • The page
          • Containers
            • Groups
            • Repeating groups
            • Table elements
            • Popups
            • Floating groups
            • Group focus
          • Visual elements
          • Input forms
            • Text and numbers
            • Dates and time
            • File uploads
            • Selection controls
        • iOS and Android app
          • The view
          • Containers
          • Visual elements
          • Input forms
          • Mobile reusable elements
        • The element hierarchy
          • The element tree
        • Reusable Elements
      • Styling
        • Color variables
        • Font variables
        • Styles
        • Custom Fonts
      • Responsive design
        • Building responsive pages
        • Legacy articles
          • The Basics (Legacy)
          • Building Responsive Pages (Legacy)
          • Migrating Legacy Pages
          • Tips When Designing (Legacy)
      • Templates
      • The Component Library
      • Importing from Figma
    • Data
      • The database
        • Data types and fields
        • Creating, saving and deleting data
        • Finding data
        • Displaying data
        • Protecting data with privacy rules
        • The database editor
        • Export/import data
          • Exporting data
          • Importing data (CSV)
        • Working with location data
        • Using Algolia
        • Database structure by app type
          • Marketplace Apps
          • Directory & Listings Apps
          • Social Network Apps
          • SaaS Apps
          • Project Management Apps
          • CRM Apps
          • Professional Services Apps
          • On-demand Apps
          • Documentation/ CMS Apps
          • Applicant Tracking System (ATS) Apps
          • Portfolio Apps
          • Gallery Apps
          • Online Store / Ecommerce Apps
          • Blog Apps
          • Messaging App
          • Dashboards
          • Building Block Apps
          • Bubble as a backend
      • Files
      • Images
      • Static data
        • App texts (translations)
        • Option sets
      • Temporary data
        • Custom states
        • URL parameters
      • User accounts
        • Authentication plugins
          • Facebook plugin
          • Fitbit plugin
          • Google plugin
          • Instagram plugin
          • LinkedIn plugin
          • Pinterest plugin
          • Slack plugin
          • Wistia plugin
          • YouTube plugin
        • Cookies set by Bubble
      • Time, dates and time zones
    • Logic
      • The frontend and backend
      • Workflows
        • Events
          • Frontend events
            • Recurring workflows
            • Custom events
          • Backend events
            • Database trigger events
        • Actions
        • API Workflows
      • Dynamic expressions
      • Conditions
      • Navigation
        • Single-page applications (SPA)
        • Multi-page applications
        • Page slugs
      • Device resources
        • Location services
        • Camera/photo library
    • Workload
      • Understanding workload
        • Activity types
        • The workload calculation
        • Client-side and server-side processing
      • Tracking workload
        • Measuring
          • Using App Metrics
        • Monitoring
          • Workload notifications
          • Infinite recursion protection
      • Optimizing workload
        • Optimization framework
        • Optimization checklist
          • Page load
          • Searches
          • Workflows and actions
          • Backend workflows
        • Agency showcases
          • Minimum Studio
          • Neam
          • Support Dept
    • Security
      • Bubble's security features
      • Planning app security
      • Client-side and server-side
      • Bubble account security
      • App security
      • Page security
      • Database security
      • API security
        • API Connector security
        • Data API security
        • Workflow API security
      • Flusk
        • Overview
        • Flusk plan features
        • Getting started with Flusk
        • Flusk security tools
          • The Issues Explorer
          • Issue details
          • Tools and settings
            • Pages rating
            • Database rating
        • Flusk FAQ
      • Cookies
      • Security checklist
    • Previewing your app
      • Previewing a web app
      • Previewing a mobile app
    • Publishing your app
      • Web app
      • Native mobile app
        • Global native mobile settings
        • iOS App Store
        • Google Play Store
        • Publishing FAQ
    • AI
      • Generate apps with AI
        • About AI app generation
      • AI page designer
      • Connect to AI agents
    • Maintenance
      • Collaborators
      • Version control
        • Best practices: Version control
        • Transitioning from the legacy version control
        • Terminology: Version control
        • Version Control (legacy)
      • Commenting
      • Database maintenance
        • Copying the database
        • Restoring database backups
        • Bulk operations
          • Bulk operation methods compared
        • Wiping change history
      • Performance
        • Hard limits
        • Capacity Usage (legacy)
        • Notes on queries
      • SEO
        • Introduction to SEO
        • SEO: App
        • SEO: Page
      • Testing and debugging
        • Introduction to testing and debugging
        • The debugger
        • The server logs
        • Supported browsers
      • API workflow scheduler
    • Integrations
      • API
        • Introduction to APIs
          • What is a RESTful API?
        • The Bubble API
          • Bubble API terminology
          • Authentication
            • How to authenticate
            • No authentication
            • As a User
            • As an admin
          • The Data API
            • Data API Privacy Rules
            • Data API endpoints
            • Data API requests
          • The Workflow API
            • Workflow API privacy rules
            • Workflow API endpoints
            • API workflows
              • Creating API workflows
              • Scheduling API workflows
              • Recursive API workflows
              • API Workflow Scheduler
              • Case: Stripe notifications
        • The API Connector
          • Authentication
          • API Connector security
          • API guides
            • OpenAI
              • Authentication
              • Calls
                • ChatGPT
                  • Chat
            • Google Translate
              • How to setup Google API keys
          • Streaming API
        • API security
        • Plugins that connect to APIs
        • API Glossary
      • Plugins
        • What Plugins Can Do
        • Installing and using Plugins
        • Authentication plugins
        • Special Plugins
      • SQL Database Connector
      • Bubble App Connector
      • WorkOS
        • WorkOS SSO
        • WorkOS API
    • Infrastructure
      • Sub-apps
      • Bubble release tiers
      • Hosting and scaling
        • How Bubble hosting works
        • Scaling with Bubble
        • CDN (Cloudflare)
        • Bubble app names
        • Domain and DNS
      • Compliance
        • GDPR
        • SOC 2 Type II
        • HIPAA
        • Other frameworks and standards
    • Bubble for Enterprise
      • Hosting and infrastructure
        • Dedicated instance
          • The Dedicated editor experience
          • Technical specs
          • Main cluster dependencies
          • Customizable options
          • Migration process
            • Pre-migration
            • During migration
            • Post-migration
      • Security and compliance
        • Single sign-on (SSO)
        • GDPR
        • SOC 2 Type II
        • HIPAA
        • Other frameworks
        • Bubble's security features
      • Admin and collaboration
      • Priority support
      • Billing and Payment Guideline for Dedicated Instances
  • Core Reference
    • Using the core reference
    • Bubble's Interface
      • Design tab
      • Design tab (Legacy)
      • Workflow tab
      • Data tab
      • Styles tab
      • Styles tab (Legacy)
      • Plugins tab
      • Settings tab
      • Logs tab
      • Template tab
      • Toolbar
      • Top and context menu options
      • Deployment and version control
        • Deployment & Version Control Dropdown (legacy)
      • Notes
    • Elements
      • Native mobile elements
        • View element
        • List component
      • General properties
      • General properties (Legacy)
      • Styling properties
      • Styling Properties (Legacy)
      • Responsive Properties
      • Responsive Properties (Legacy)
      • Conditional formatting
      • States
      • Page Element
        • Page Element (Legacy)
      • Visual Elements
      • Containers
      • Container Layout Types
      • Containers (Legacy)
      • Input Forms
      • Reusable Elements
      • Element Templates (legacy)
    • Workflows
    • Events
      • General events
      • Element events
      • Custom events
      • Recurring event
      • Database trigger event
    • Actions
      • Account
      • Navigation
      • Data (things)
      • Email
      • Element
      • Custom
    • On-device resources
    • Data
      • Data Sources
      • Operators and comparisons
      • Search
      • Privacy
    • Styles
    • API
      • The Bubble API
        • The Data API
          • Authentication
          • Data API endpoints
          • Data API requests
        • The Workflow API
      • The API Connector
        • Authentication
        • Adding calls
    • Bubble-made Plugins
      • AddtoAny Share Buttons
      • Airtable
      • API Connector
      • Blockspring
      • Box
      • Braintree
      • Bubble App Connector
      • Chart.js
      • Circle Music Player
      • Draggable Elements
      • Dropzone
      • Facebook
      • Fitbit
      • Full Calendar
      • Google
      • Google Analytics
      • Google Optimize
      • Google Places
      • Ionic Elements
      • iTunes
      • Slidebar Menu
      • LinkedIn
      • Localize Translation
      • Mixpanel
      • Mouse & Keyboard Interactions
      • Multiselect Dropdown
      • Progress Bar
      • Rich Text Editor
      • Rich Text Editor (Legacy)
      • Screenshotlayer
      • SelectPDF
      • Slack
      • Segment
      • Slick Slideshow
      • SQL Database Connector
      • Star Rating
      • Stripe
      • Tinder-like Element
      • Twitter
      • YouTube
      • Zapier
    • Application Settings
      • App plan
      • General
      • Domain / email
      • Languages
      • SEO / metatags
      • API
      • Collaboration
      • Sub-apps
      • Versions
  • Account & Marketplace
    • Account and billing
      • Pricing and plans
        • Plans and billing
        • Billing cycle
        • FAQ: Pricing and Workload
      • Account Management
      • Building Apps for Others
      • Selling on the Marketplace
      • Plans & Billing (legacy)
    • Official Bubble Certification
      • Hiring certified developers
    • Building Plugins
      • The Plugin Editor
      • General Settings
      • Updating to Plugin API v4
      • Adding API Connections
      • Building Elements
      • Building Actions
      • Loading Data
      • Publishing and versioning
      • Github Integration
    • Building Templates
    • Application and data ownership
    • Marketplace policies
    • Bug reports
  • Vulnerability Disclosure Policy
  • Beta features
    • About the Beta features section
    • Native mobile apps
Powered by GitBook
On this page
  • What are custom events for?
  • Creating a custom event
  • Parameters
  • Return values
  • Running a custom event
  • Triggering
  • Scheduling
  • FAQ: Custom events

Was this helpful?

  1. User manual
  2. Logic
  3. Workflows
  4. Events
  5. Frontend events

Custom events

This section covers Custom events. They are events that can be triggered by other workflows to avoid duplicating workflows, as well as triggered inside a reusable element.

This article covers frontend Custom events – there are also custom events available in the backend.

Custom events are events that can only be triggered by using the Trigger a custom event action. In other words, they have to be triggered by another workflow. They can accept parameters that can be referenced in the action steps inside of the workflow.

You can trigger custom events that are on the same page, or inside of a reusable element that's directly placed on the page you are currently working on by using the Trigger a custom event from a reusable element action.

What are custom events for?

Custom events have several useful usages:

Avoid repeating work

Since custom events can be called from anywhere on the page, you can avoid having to duplicate workflows.

For example, let's say you have an application that handles documents; you have one Save menu option under File - Save, and another as an icon in a toolbar. The two do exactly the same thing; they save the contents of a input field to the database.

Instead of using two identical workflows to save the document, you can place the actions needed to save it in a custom event, and trigger that workflow from both places.

Returning data

You can also return data with custom events. For example, you can:

  • Check something in the database or an external service

  • Make calculations

  • Generate dynamic data

  • Validate forms

Maintain consistency and prepare for future changes

Custom events also help you standardize things that happen in your application. Let's say for example that you use a to show messages to your users such as The changes have been saved. By using a custom event to show that popup, you can ensure that it looks and behaves the same no matter what the message is. Should you later decide to move away from a popup and instead use an you can make that change in just one workflow and it will be replaced all across the page.

Control the order of operations in a workflow

Custom events give you a more fine-grained control over the order of operations in a workflow.

Creating a custom event

To create a custom event, first navigate to the Workflow editor, and click Click here to add an event... . From the dropdown menu, pick Custom and Create a new custom event.

Parameters

  1. First, we give the event a name. The name doesn't affect how it works, but it's useful to make it descriptive and easy to recognize

  2. Then, we'll set up two parameters by clicking the Add a new parameter button. Parameters let you pass any kind of data to the workflow, and use that information in actions inside of that workflow.

    1. First, we'll pass a user: that is the user who's name we want to change

    2. Then, we'll pass a text: this is the new name that the user will be given

Now we have a custom event that accepts two things: a user and a text. Let's reference those in an action:

We'll add a Make changes to a thing action.

Make sure to use the Make changes to a thing action, and not the Make changes to current user actions, since we will be using a parameter to determine which user to make changes to.

In the thing to change we choose user, which is the name we gave the first parameter. Then we pick the Name field on the user, and set it to text, which is the name of the second parameter.

This way, we have set up a custom event that can change the name of any user by asking for it as a parameter. By setting up custom events for key workflows in your app, you can make sure they work consistently and are not duplicated across your app.

Return values

You can also set up a custom event to return one or more values of a specific data type. Let's expand our user example. Instead of changing the user's name, we want to start a via the. The result can be successful, or not succesful, depending on the user's payment credentials, and we want to return the result after the actions in the custom event are finished running.

Adding the return values

First, select the custom event. The event properties will be displayed. Under return values, we'll include two points:

Value name
Data type
Purpose

Success

yes/no

Return whether the subscription was successfully started

Error code

text

If not, we want to return the error code from Stripe

We'll set it up as in the screenshot below:

A few things are worth noting in the image above:

  • We are still sending a user parameter, to instruct the custom event to start the subscription on a specific user

  • Return values are created under the Return values header – not to be confused with parameters

  • We have set the subscription value as required, since we'll always return a yes or no

  • The error message is set to optional, since we only need to return a value if the subscription is unsuccessful

Setting up the actions

If you want to replicate this specific custom event, you will need to install the Stripe plugin from the plugin store.

Now, let's set up the actions that will attempt to start a subscription.

  1. First, we'll use the Subscribe user to a plan action to start the subscription on the user provided in the parameters.

  2. In step 2, we use the return data action to send data back.

  3. We'll leave the Error message return value blank, since this action will only run if the subscription is successful

  4. We are using the Only when field to only send yes if Stripe returns the status active. This step terminates the workflow – any steps after this will not run if the Only when returns yes.

With that set up, we are returning a yes to the original workflow that triggered the custom event. Now let's look at Step 3, which runs if the subscription was not successful.

  1. First, we're return a no instead of a yes

  2. This time, we'll also return the error message. The Stripe plugin (which connects to the Stripe API) returns a field called status which lets us know whether is was successful or not.

  3. If that field does not contain the text active, then the subscription failed – Stripe will return a string to let us know what went wrong.

Keep in mind that whenever a return data action runs (and is not stopped by a condition), the workflow stops running. In other words, any subsequent steps will not trigger, similar to the Terminate a workflow action.

Using the returned data

The data will be "returned" to the original workflow. Let's have a look at how you access that data:

In the first step we're triggering the event (see more about this in the section below). We're not returning any data until the next step.

  1. We're using the Show message in Alert action to show the error message to the user. Note that you need to place an Alert element on the page before this action is available.

  2. In the custom message, we'll use the Result of step 1 data source. Step 1 in this case was the triggering of the custom event, so this lets us access the returned data.

  3. In the third step, we're checking whether an error was generated.

In a real-life example, you may take more action than this, but this illustrates how you can use custom events to perform a series of actions and return dynamic data based on those actions.

Running a custom event

Triggering

A custom event can be triggered instantly by using the Trigger a custom event action.

Trigger a workflow in a reusable element

By placing a custom event inside of a reusable element, that workflow can be triggered from the parent of that reusable element. For example, if you have a page called index and you place a reusable element called popup-message on that page, you can trigger any custom event inside of popup-message from the index page (and any other page where you place the reusable element).

Note: Triggering custom workflows works only in one direction: from the parent page to the child reusable element.

Scheduling

A custom event can also be scheduled to run at a specific time by using the Schedule a Custom event action and providing a number of seconds of delay before the event should trigger.

Scheduling a custom event is a client-side action, and consequently it will not run if the page is closed. If you want to schedule a workflow to run even if the user has closed the app, you can use server-side API workflows:

Is there a difference between triggering a custom event and scheduling a custom event to occur with a 0 second delay?

Yes, there is.

Let's say you have a parent workflow that has some actions, then a "Trigger a custom event" action, then some more actions. When the parent runs that Trigger action, the parent will pause and wait for the custom event to complete before running the actions that come after it. This is convenient in part because the custom event will be able to see the context of what happened in the actions before it in the parent workflow.

In contrast, if you schedule the custom event to occur with delay 0, that custom event could end up running in parallel to the rest of the parent workflow.

How are custom events executed?

Whenever a custom event is triggered inside of another workflow, the workflow will stop at that point, run the custom event until it is completed, and then move on to the next action in the "parent" workflow. You can use this to control some aspects of how workflows are triggered. You can read more about how workflows are triggered in the link below.

FAQ: Custom events

You will get this error when one or more of the Return data parameters are required (not set to optional) and the workflow does not have a Return data action, without a condition, as its last step. When a return data field is required, the workflow has to return something.

There are two ways to solve this:

  • Add an unconditional action as the last step of the workflow, and return whatever data you need to

  • Change the Return data parameter to be optional. This way a condition is accepted.

Can I loop a custom event?

Custom events cannot be looped, and as such a custom event cannot trigger itself. If you want to repeat a workflow more than once on a list of things, you can consider using , and set up an that completes the action.

Last updated 1 month ago

Was this helpful?

Article section: Video:

Article series:

Article: Scheduling

Article section:

I get the error "This workflow must end with a unconditional 'Return Data' action"

The order in which actions are triggered
Understanding workflow execution rules
The Workflow API
API Workflows
The order in which actions are triggered
Issue Checker