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
Step-by-step
1. Form Trigger
Add a Form Trigger with the title Purchase order request and these fields:
| Label | Type | Required |
|---|---|---|
| Requester 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 approvedafter the Approval node's Approved outputRecord auto-approvedafter the If'sfalseoutput
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:
{{ $trigger.payload.requester }}{{ $trigger.payload.vendor }}{{ $trigger.payload.amount }}{{ $trigger.payload.description }}approvedinRecord approved,auto-approvedinRecord 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
- Open the form link and submit a request for $100.
- The run takes the
falsepath, records the order asauto-approved, and emails you.
- The run takes the
- 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
approvedand 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.