On this page
Sommatic Docs
Open portal

Recipes

Expression patterns that work in production workflows — reading earlier nodes, building typed objects, defensive conditions, dates in a time zone, safe URLs, defaults and lists — ready to copy into a node field.

View as Markdown
Open in

Each recipe says which field kind it needs: pure (the whole field is the expression and keeps its type) or mixed (text around the expression, the result is text). Replace the node labels with the labels of your workflow.

Read a field from an earlier node

Pure or mixed. The most common expression in production:

JavaScript
{{ $('Normalize input').item.json.correlation_id }}

Read the webhook request

Right after a webhook trigger, the request is the input ($json). Further down, read it from the trigger by label:

JavaScript
{{ $json.body.email }}
{{ $('Webhook Receiver').item.json.body.email }}
{{ $('Webhook Receiver').item.json.query.source }}

Build a typed object

Pure. Wrap object literals in parentheses, otherwise the braces are read as a block of code:

JavaScript
{{ ({ id: $json.id, received: $now.toISO(), run: $execution.id }) }}

Use it for a request body, the output of a data.transform or the payload of a task.

Write a defensive condition

Pure, for flow.if. When the data you read may be missing, wrap the logic in a function that you call at once, and return false if anything fails:

JavaScript
{{ (function () { try { var result = $('Classify').item.json || {}; return (result.confidence || 0) >= 0.7; } catch (error) { return false; } })() }}

For short checks, optional chaining is enough:

JavaScript
{{ ($('Classify').item.json.confidence ?? 0) >= 0.7 }}

Format dates in a time zone

Pure or mixed. $now uses the server’s zone; set yours first:

JavaScript
{{ $now.setZone('America/Bogota').toFormat('yyyy-LL-dd HH:mm') }}
{{ $now.setZone('America/Bogota').plus({ days: 3 }).toISODate() }}
{{ $today.minus({ months: 1 }).toFormat('LLLL yyyy') }}

Build safe URLs

Mixed. Encode every value that goes into a path or query:

JavaScript
https://api.example.com/items/{{ encodeURIComponent($json.key) }}
https://api.example.com/search{{ $toQueryString({ q: $json.body.term, page: 1 }) }}

Fall back to a default

Pure or mixed:

JavaScript
{{ $ifEmpty($json.body.priority, 'normal') }}
{{ $json.customer?.name ?? 'Customer' }}

Filter, map and sum lists

Pure:

JavaScript
{{ $json.items.filter(item => item.qty > 0).map(item => item.sku) }}
{{ _.sumBy($json.items, 'qty') }}
{{ $jmespath($json, 'items[?status == `open`].id') }}

Use an optional branch

Pure. Read a node only if it ran in this execution:

JavaScript
{{ $('Enrich customer').isExecuted ? $('Enrich customer').item.json.segment : 'unknown' }}

Put a traceable reference in a message

Mixed. $execution.id is shared by every run of a workflow.chain, so one reference follows the whole case:

JavaScript
We received your request. Reference: {{ $execution.id }}

Read the result of a code node

code.js and code.python wrap what they return in result:

JavaScript
{{ $('Compute totals').item.json.result.total }}

Join values into one piece of text

When a field would start and end with an expression, write a single expression that concatenates:

JavaScript
{{ $json.first_name + ' ' + $json.last_name }}
{{ `${$json.prefix}-${$json.number}` }}

Next steps

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs