Workflows

How to save, update or delete database records with a workflow

How to save, update or delete database records with a workflow

In a TeleportHQ workflow, you work with your database using the steps in the Data category: Create Item adds a record, Update Item changes records, Delete Item removes records, and Select Data and Count Data read them. Add the step, pick the Data Source and Collection/Table, then fill in the values, usually from a form or an earlier step.

Before you start

Steps: save a form submission as a new record

This example saves each Order cake form submission as a row in a bakery's orders table.

  1. Open the workflow. Point at the trigger's box and click the round + (Add node) below it. Below the last box of a workflow, the + always shows.
  2. In the Add Node menu, point at Data and click Create Item.
  3. In the right panel, open Data Source and pick your database, for example the TeleportHQ database. Use Search data sources... if you have several.
  4. Open Collection/Table and pick orders.
  5. Under Column Values, fill each column. Drag a value from the Context panel onto the field, or click the field's Select from context button and pick it:
    • customer_name: the form's name value.
    • cake_type: the form's cake value.
    • status: type new.
  6. Leave Wait For The Result ticked ("Await this node before running the next one") if a later step needs the new record, for example to show its order number.

Columns you leave empty are left out, so the database's default value applies. See How to use data from one workflow step in the next.

The TeleportHQ Create Item step settings with the Data Source, Collection/Table and Column Values fields highlighted

Steps: update or delete records

  1. Add Update Item or Delete Item from the Data category.
  2. Pick the Data Source and Collection/Table.
  3. Under Filtering, click Add filter. Choose a column, an operator and a value, for example id = the order ID from an earlier step. The filter decides which rows are changed.
  4. For Update Item, fill Column Values with the new values, for example status: ready. Columns you leave empty keep their current value.
The TeleportHQ Update Item step settings with the Filtering section highlighted

Steps: read records

  1. Add Select Data (returns rows) or Count Data (returns a number).
  2. Pick the Data Source and Collection/Table.
  3. On the Configuration tab, choose Columns to Select, add filters and sorting, and set Limit and Skip if needed.
  4. Later steps can use the result, for example to send the rows in an email. See How to use data from one workflow step in the next.

If you know SQL, use the Raw Query tab of Select Data or the Raw SQL Query step. Click Insert Variable to add values from earlier steps.

Check that it worked

  • Right-click the step and choose Test this node…, then Run test. The test really writes to your database. Every test you run is listed on the Test runs tab of the right panel. See How to test a workflow step.
  • Open the table in Data Sources and check the new or changed row. See How to view, add and edit records.

Troubleshooting

"No data sources yet" The project has no database. Click Create TeleportHQ Database in the step to create one, then create a table.

The table I need isn't in the list Check that it exists in the selected data source. You can also click Create new table in the table list.

"Publishing Blocked": "Your project cannot be published because 1 workflow node contains forbidden SQL operations" A raw SQL query uses an operation that isn't allowed in workflows, for example DROP or ALTER. Only SELECT, INSERT, UPDATE and DELETE are allowed. Click Go back and fix, then change the query. Change your table structure in Data Sources instead.

A red "Security: SQL Schema Leak" icon on a data step The step builds or passes a SQL query through the visitor's browser. Write the SQL in the data step as fixed text and pass changing values as parameters ($1, $2, …).

"This column is no longer part of the selected table. Clear its value to remove the mapping." The column was deleted or renamed. Clear that value.

A later step receives nothing from the data step Wait For The Result is off: the step shows "This node's result is null." With it off, the step's errors also don't stop the workflow. Tick Await this node before running the next one.

Good to know

  • A form whose submit runs a workflow stops saving submissions in Forms. The workflow owns the submission, so add a Create Item step if you want to keep the data. See How to create a form.
  • AI can build it for you. In the workflow's AI Assistant tab, ask for example "Save the Order cake form to the orders table". If the table doesn't exist yet, the AI can create it too. See How to build a workflow with AI.
  • Deleting a table or data source that workflows use asks for confirmation and resets the table choice in those steps.
  • To let AI answer questions from your data, use AI: Select Database Data in the AI category. It only reads data.
  • For store orders, products and carts, use the E-Commerce steps instead.
Share

Related Articles

What are workflows?

A workflow in TeleportHQ is a visual recipe that makes your web app do something, one trigger (like a button click or a form submission) followed by steps (like saving to a database, sending an email or opening a page), built without writing code; adding one makes a website a web app.

How to use data from one workflow step in the next

In a TeleportHQ workflow, every step can use the results of the trigger and earlier steps (the workflow Context), by dragging a value from the Context panel onto a field or picking it with the Select from context button.

How to set up the built-in TeleportHQ database

To add the built-in TeleportHQ database, open Data Sources in the editor's left sidebar, click + (Add Data Source), choose TeleportHQ database and click Setup TeleportHQ Database; TeleportHQ creates a hosted database for the project that you then fill with tables.

How to create database tables (by hand or with AI)

In TeleportHQ, you create tables from the Add a new table card of your database in the Data Sources panel, either by filling in the Create New Table form or by describing the tables you need in the Create Tables with AI window.

How to test a workflow step

In TeleportHQ, click a workflow step and click Test in the right panel (or right-click the step and choose Test this node…), fill in sample values for the data it needs, then click Run test to run that one step for real and see its output; the Test runs tab lists every test of the workflow.

Why does my workflow show missing configuration or security warnings?

TeleportHQ shows a yellow "N issues" button at the top left of the editor when workflow steps still need keys, pages, elements or states (it opens the Issues window), a "N security issues" button when workflow code could leak secrets or run unsafe SQL (critical ones block publishing), and a "Not exported" badge on a workflow that can never run; each one leads you to the step to fix.