# Custom Events

From the Bubble manual:

> *Custom events are a way to define a workflow in your page that can be reused multiple times ("functions" in a code-driven language).*

You will find multiple uses of custom events in the template.&#x20;

<figure><img src="/files/DKFasMziSpDWXtpzCqJ3" alt=""><figcaption><p>Dedicated custom events for sending emails. You will find these in 👥 USER ACCESS MANAGEMENT reusable.</p></figcaption></figure>

Read more about the basics of Custom events in [Bubble manual](https://manual.bubble.io/help-guides/building-workflows/using-custom-events).

Advanced practices of using Custom events are based on the connection between Custom events and Reusable elements (you can read about the basics of Reusable elements in [Bubble manual](https://manual.bubble.io/help-guides/structuring-an-application/reusable-elements))&#x20;

Reusable elements can be used as sections with UI's or just workflows (no UI). A great use case for creating reusable with only workflows in it is for example integrating payments in your app. Workflows created in one place could be then reused on multiple pages throughout your app.&#x20;

{% hint style="info" %}
We are heavy proponents of Custom events as we try to avoid duplicate work as much as we can. Custom events are a great tool to keep your workflows lean, your debugging time short and your teammates happy.&#x20;
{% endhint %}

Read how we use custom events and reusable elements together [in this section](/working-with-the-framework/data-and-workflows/crud.md).

### Workflow execution rules

Bubble actions do NOT run sequentially. Most of the time actions will not be completed in the same order as they are triggered.&#x20;

In the example below you cannot be sure that every time you run this workflow step 3 will be executed after step 1 and step 5 will always be before step 2 etc. The execution order is dependent on the type of action of client-side criteria (e.g. the newly created object needs to be displayed immediately on the page etc.)

<figure><img src="/files/ouTmjB0QDZqDwNymrtA0" alt=""><figcaption><p>Example</p></figcaption></figure>

There are two ways you can force Bubble to run your actions sequentially:

a) Use 'Result from Step X' in your conditional logic. For example 'Result of step 1 unique id is not empty'

b) use Custom Events. In the example below Bubble will first trigger Custom Event A meaning all actions inside the Custom Event will be run *before* triggering Custom Event B.

<figure><img src="/files/Ch6dVnlbr9LxWByHnPrm" alt=""><figcaption></figcaption></figure>

From [Bubble manual](https://manual.bubble.io/help-guides/building-workflows/using-custom-events#execution-of-a-custom-event):

> *When a workflow is triggered in Run-mode and hits a trigger a custom event action, the first workflow will pause, the custom event will be run till completion, and the first workflow will resume. Using the debugger can be very helpful to understand the flow of actions if you are hitting some difficulties setting things up*

Learn more about order of execution from this Bubble video:

{% embed url="<https://www.youtube.com/watch?v=IbhCrciOKHM>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.openbuild.io/working-with-the-framework/data-and-workflows/custom-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
