Skip to content

Tutorials

Tutorial: data tables and decision tables

Create a data table, save and read rows from a workflow with the Data step, and build a decision table that picks the approver for a Decision Table step.

Last updated 3 min read Edit this page on GitHub
On this page

Goal: save every expense claim in a data table, and let a decision table decide who approves it by amount.

You need: Create tables and Edit schema (data.create, data.edit_schema) for data tables, and Edit workflows for business rules and workflows. Owner, Admin and Manager have them.

Time: about 20 minutes. It builds on the approval workflow tutorial, but works with any workflow.

1. Create a data table#

  1. Go to Build › Data and select New table.
  2. Enter the Name Expenses and select Create table.
  3. On the Schema tab, select Add column for each column, then Save changes:
NameTypeRequired
TitleTextyes
AmountNumberyes
StatusText
ApproverText

Column keys are made from the names (title, amount, status, approver). The Rows tab shows the data, and Access sets who can see and change it.

A data table with rows
A data table: rows, schema and access.

2. Save a row from a workflow#

In your workflow, after the trigger, add a Data step:

  1. Data table: Expenses. Operation: Insert.
  2. Map the columns: Title = {{form.title}}, Amount = {{form.amount}}, Status = Pending.
  3. The new row's id is saved as {{row_id}}.

Later in the workflow, add another Data step with Update, find the row by Row ID {{row_id}}, and set Status to {{outcome}}.

Data step: insertJSON
{
  "table_id": "<table-id>",
  "table_name": "Expenses",
  "operation": "insert",
  "column_values": { "title": "{{form.title}}", "amount": "{{form.amount}}", "status": "Pending" },
  "output_row_id_var": "row_id"
}

List reads several rows with filters (for example Status Equals Pending) into {{rows}} and {{row_count}}. Get reads one row into {{row}}.

3. Ask the Agent to add sample rows (optional)#

To try things out, let the built-in Agent fill the table for you. On the Expenses table, open the Agent panel and ask:

The Agent shows a preview of the first rows and the count. Select Confirm to add them. Later you can ask "Delete the sample rows": it lists the rows and asks you to confirm with a red Delete N rows button (over 25 rows, you also type delete N). You need Manage rows on the table. See Using the Agent.

4. Build a decision table#

  1. Go to Govern › Business rules and select New decision table. Name it Approval policy.
  2. Under Inputs, select Add input: key amount, type Number.
  3. Under Outputs, add approver (Text) and needs_cfo (Boolean).
  4. Under Rules, select Add rule for each row. Rules run top to bottom, and the first enabled rule whose conditions all match wins:
RuleConditionapproverneeds_cfo
Smallamount Less than 500team-leadfalse
Mediumamount Less than 5000managerfalse
Large(no conditions: catches everything else)cfotrue
  1. Select Test rules, enter an amount of 7500, and check that Large matches. Then Save.
The decision table editor with inputs, outputs and rules
A decision table: inputs, outputs and first-match rules.

5. Use it in the workflow#

  1. Add a Decision Table step before the User Task. Choose Approval policy.
  2. Map the input amount to {{form.amount}}.
  3. The outputs become variables: {{approver}}, {{needs_cfo}}, and {{rule_label}} (the rule that matched). {{matched}} is false when no rule matched.
  4. Use them downstream. For example, add a Branch by Condition on {{needs_cfo}} is_true, or save {{approver}} to the row's Approver column.
Decision Table stepJSON
{
  "decision_table_id": "<decision-table-id>",
  "decision_table_name": "Approval policy",
  "input_mappings": { "amount": "{{form.amount}}" }
}

Changing the rules takes effect at once for every workflow that uses the table. There is no draft, so test with Test rules before you save.

What you built#

  • A data table that every run writes to and updates.
  • A first-match decision table with a catch-all rule, tested in the editor.
  • A workflow step that sends values into the table and branches on its answer.

Next steps#

Was this page helpful?