Skip to content

Recipe 04: Approval-routed purchase order

Goal: a form submission for a purchase order is approved automatically if it is $1,000 or less. Larger orders go to a finance approver by email. Approved orders are recorded in a database.

Difficulty: Intermediate · Time: about 30 minutes · Connectors: Form Trigger, Database (Postgres), Email


Prerequisites

  • A Postgres database Flero can reach, with this table:
    CREATE TABLE purchase_orders (
      id          serial PRIMARY KEY,
      requester   text,
      vendor      text,
      amount      numeric,
      description text,
      status      text,
      created_at  timestamp DEFAULT now()
    );
  • The email address of your finance approver. They do not need a Flero account: the approval email carries a link they can open without signing in.
  • A way to send email from workflows (see Recipe 03).

Finished workflow

Workflow: Form Trigger to Over 1,000?, Over 1,000? to Finance approval, Over 1,000? to Record auto-approved, Record auto-approved to Confirm order, Finance approval to Record approved, Record approved to Confirm approval, Finance approval to Explain decline Form TriggerTrigger on form Over 1,000?IfFinance approvalApprovalRecord approvedDatabaseRecord auto-approvedDatabaseConfirm approvalEmailExplain declineEmailConfirm orderEmail

Step-by-step

1. Form Trigger

Add a Form Trigger with the title Purchase order request and these fields:

Label Type Required
Requester email Email Yes
Vendor Text Yes
Amount Number Yes
Description Text Area No

Each submission starts a run. The answers are in $trigger.payload, keyed by each field's internal ID, such as field_1760000000000. This recipe writes requester, vendor, amount and description in place of those IDs for readability. Submit the form once, then insert the real paths with the data picker. See Form trigger.

2. If: amount over 1,000

Add an If node after the Form Trigger with one condition:

  • Value 1: {{ $trigger.payload.amount }}
  • Operator: greater than
  • Value 2: 1000

3. Approval branch (true)

From the If's true output, add an Approval node named Finance approval:

  • Approval Type: Email
  • Message:
    {{ $trigger.payload.requester }} is requesting ${{ $trigger.payload.amount }} for {{ $trigger.payload.vendor }}.
    
    Reason: {{ $trigger.payload.description }}
  • Approvers: your finance approver's email address
  • Require Comment: on, so the approver explains a rejection

The run pauses until someone decides. The approver gets an email with a link to decide. Anyone in the workspace can also decide from Approvals in the app. See Approval basics.

4. Record approved orders

Add two Database nodes, one for each path:

  • Record approved after the Approval node's Approved output
  • Record auto-approved after the If's false output

Configure both the same way, except for the status value:

  • Mode: Remote, with your Postgres connection details
  • Read only: off
  • Operation: Insert
  • SQL:
    INSERT INTO purchase_orders (requester, vendor, amount, description, status)
    VALUES ($1, $2, $3, $4, $5)
  • Parameters:
    1. {{ $trigger.payload.requester }}
    2. {{ $trigger.payload.vendor }}
    3. {{ $trigger.payload.amount }}
    4. {{ $trigger.payload.description }}
    5. approved in Record approved, auto-approved in Record auto-approved

Form data is still available after the pause, so $trigger.payload works on both paths.

5. Email the requester

After each Database node, add an Email node:

  • To: {{ $trigger.payload.requester }}
  • Subject: Your purchase order for {{ $trigger.payload.vendor }} is approved
  • Body: a short confirmation

From the Approval node's Rejected output, add one more Email node telling the requester the order was declined.

6. Save and activate

Save, then set the workflow to Active in the editor toolbar's version menu. Copy the form's public link from the Form Trigger's inspector.


Try it

  1. Open the form link and submit a request for $100.
    • The run takes the false path, records the order as auto-approved, and emails you.
  2. Submit a request for $5,000.
    • The run pauses at Finance approval with status Waiting.
    • The approver receives the email, opens the link and approves.
    • The order is recorded as approved and the confirmation email arrives.

Variations

Two sign-offs for very large orders

The first decision on an Approval node settles it. To require two people, chain two Approval nodes: connect the first node's Approved output to a second Approval node with a different approver. Add a second If in front, for example amount > 50000, so only the largest orders need both. See Multiple approvers.

Notify the team on submission

Add a Slack node right after the Form Trigger that posts the request to #purchasing.


Troubleshooting

Symptom Likely cause Fix
Submitting the form starts no run The workflow is not active Activate the workflow
The approver gets no email Approval Type is not Email, or the address is wrong Set Approval Type to Email and check the Approvers list
Every order goes to approval The If compares text instead of numbers Check the amount field type is Number
The Database node refuses the insert Read only is on Turn Read only off
The run waits for days Nobody decided Decide from Approvals, or stop the run. Approval requests sent by email do not time out.

Next


Found something out of date? This page lives in the Flero docs content set.