Build your first workflow
Build a workflow that flags every order over 100 for review the moment it's created, then read its job history to see it run. About ten minutes.
Last updated
You'll build a workflow that watches for new orders and writes a review record for any order of 100 or more. Along the way you'll use an event trigger, a trigger filter, a Create Data step and a template, then read the job to see exactly what happened.
Every step is shown three ways: in the Anythink dashboard, with the CLI and with an AI assistant over MCP. Pick one and follow it through, or mix them. They all change the same project. If you'd like the idea first, read How workflows work.
Before you start
You need a project and two entities. If you built orders in Build your first app, add the missing fields to it; otherwise create both from scratch.
| Entity | Fields |
|---|---|
orders |
customer_email (text), total (decimal), status (text) |
order_reviews |
order_id (integer), note (text) |
In the Anythink dashboard
- Go to Settings › Data Model and select Add Entity.
- Enter
ordersas the Entity Name and select Create Entity. - Open the entity and select Add Field for
customer_email(Small text),total(Decimal) andstatus(Small text). - Repeat for a second entity,
order_reviews, withorder_id(Integer) andnote(Large text).
With the CLI
anythink entities create orders
anythink fields add orders customer_email --type varchar
anythink fields add orders total --type decimal
anythink fields add orders status --type varchar
anythink entities create order_reviews
anythink fields add order_reviews order_id --type integer
anythink fields add order_reviews note --type text
With an AI assistant (MCP)
Create an orders entity with customer_email (text), total (decimal) and status (text). Then create an order_reviews entity with order_id (integer) and note (text).
The assistant runs entities create and one fields add per field through the cli tool. See Model your data for every field type.
Step 1: Create the workflow and its trigger
A trigger decides when the workflow starts. This one is an Event trigger on the orders entity, set to fire when an order is created. A trigger filter adds a condition, so the workflow only starts when total is at least 100. Orders under 100 never create a job.
In the Anythink dashboard
- Open Workflows and select New Workflow.
- Enter the Name
flag-large-orders. - Under Triggers, leave Trigger Type as Event. Set Event Type to Entity Created and Entity to
orders. - Under Fire only when…, select Add filter. Set the field to
total, the operator to ≥ and the value to100. - Leave Enable Workflow cleared for now, then select Create Workflow.
The editor opens with a Start node on the canvas.
With the CLI
anythink workflows create flag-large-orders \
--trigger Event \
--event EntityCreated \
--entity orders \
--filter '{"field":"total","op":"gte","value":100}' \
--enabled
✓ Workflow flag-large-orders created (id: 42).
Note the id it prints. The CLI enables the workflow as it creates it. Nothing runs until an order arrives, and you add the step next.
With an AI assistant (MCP)
Create a workflow called flag-large-orders that runs when an order is created and its total is at least 100, and enable it.
The assistant runs workflows create with an event trigger and a filter through the cli tool, and tells you the workflow's id.
Step 2: Add the step
A step is one action. Create Data writes a record. Its parameters can contain templates: {{ … }} expressions that Anythink fills in just before the step runs.
{{ $anythink.trigger.id }}is the id of the order that started the job.{{ $anythink.trigger.data.customer_email }}is a field from that order.
When a template is the whole value of a field, it keeps its type, so order_id receives a number. When it sits inside longer text, as in note, it's written into the text.
In the Anythink dashboard
- In the editor, select Add Step and choose Create Data.
- Enter the Name
Create reviewand the Keycreate_review, and tick Enable Step. - Set Entity to
order_reviews. - Set the Payload:
{
"order_id": "{{ $anythink.trigger.id }}",
"note": "Order from {{ $anythink.trigger.data.customer_email }}, total {{ $anythink.trigger.data.total }}, needs review"
}
- Save the step. On the canvas, drag from the Start node to the step's input to make it the start step.
- Select Save Workflow, then select Enable Workflow in the toolbar.
With the CLI
In a CLI step the payload is a string that holds JSON, so its inner quotes are escaped. Use the workflow id from the previous step:
anythink workflows step-add 42 create_review \
--name "Create review" \
--action CreateData \
--start --enabled \
--params '{"entity_name":"order_reviews","payload":"{\"order_id\":\"{{ $anythink.trigger.id }}\",\"note\":\"Order from {{ $anythink.trigger.data.customer_email }}, total {{ $anythink.trigger.data.total }}, needs review\"}"}'
✓ Step create_review (id: 82) added to workflow 42.
--start makes it the step the job begins with.
With an AI assistant (MCP)
In workflow 42, add a Create Data step called create_review that writes to order_reviews, and make it the start step.
The assistant runs workflows step-add through the cli tool. Then open the step in the Anythink dashboard and add the two templates from the dashboard steps above to its payload.
Step 3: Test it
Create one order that should be flagged and one that shouldn't.
In the Anythink dashboard
- Open the
ordersentity and select Create Order. - Enter
sam@example.com, a total of149.50and statusnew, then save. - Create a second order with
ali@example.com, a total of24and statusnew.
With the CLI
anythink data create orders --data '{"customer_email":"sam@example.com","total":149.50,"status":"new"}'
anythink data create orders --data '{"customer_email":"ali@example.com","total":24.00,"status":"new"}'
With an AI assistant (MCP)
Create two orders: one for sam@example.com with a total of 149.50 and status new, and one for ali@example.com with a total of 24 and status new.
The assistant runs data create twice through the cli tool.
Step 4: Check it worked
Each run of a workflow is a job. It keeps the payload that started it and the log and output of every step.
In the Anythink dashboard
- Open the workflow and select View Job History.
- There is one job, for the 149.50 order, with the status Success. Open it to see the Payload it received and each step under Execution Steps.
- Open the
order_reviewsentity. There is one record: "Order from sam@example.com, total 149.5, needs review".
With the CLI
anythink workflows jobs 42
anythink data list order_reviews --json
The first command lists the workflow's jobs and their statuses: one, with status Success. The second shows the review the step created:
[
{
"id": 1,
"order_id": 1,
"note": "Order from sam@example.com, total 149.5, needs review"
}
]
The output also includes created_at, updated_at and a few other system fields.
With an AI assistant (MCP)
List the order_reviews records.
The assistant runs data list order_reviews through the cli tool. Open the workflow's View Job History in the dashboard to see each job.
The 24 order didn't match the filter, so it left no job at all. To see a job's step log in full, use the dashboard's View Job History. Test workflows and read job history covers reading jobs, running a workflow by hand and tracking down failures.
What you built
| Part | What it did |
|---|---|
| Event trigger | Started a job whenever an order was created |
| Trigger filter | Skipped orders under 100 before any job was created |
| Create Data step | Wrote a review record |
| Templates | Filled the review with the order's id and fields from the trigger data |
| Job history | Recorded what the job received and what each step did |
Take it further
- Notify someone. Add a Send an Email step after
create_reviewto email your support inbox. See Send email from a workflow. For a push notification instead, see Push notifications from a workflow. - Handle a failure. Every step has a green on success handle and a red on failure handle on the canvas. Connect the red one to a step that logs the problem or sends a message, so a failed step doesn't end the job as failed. How workflows work explains the paths.
- Only flag paid orders. Change the event to Entity Updated and the filter to
statuschanged topaid. See Triggers and scheduling. - Call another system. Add a Call An API step that sends the order to a partner, with its key kept in Secrets. See Webhooks.
Next steps
- How workflows work: triggers, steps, templates, jobs and limits
- Triggers and scheduling: events, schedules, manual buttons and API routes
- Step types: every step and its parameters
- Template syntax: every
{{ }}expression a step accepts - Test workflows and read job history: read jobs and fix failures