Skip to content
Agentic Workflowdocs
v0.9.0Install free

concepts / data

Processing data with code

When a mapping isn't enough, reshape items with JavaScript or Python in a code step.

Most changes need no code: tap a field into a setting, write an expression, use Edit Fields, or Summarize items for totals per group. Use a code step when you need to:

  • reshape items with logic that doesn’t fit in one expression;
  • parse an unusual format (Python’s standard library has re, json, csv, datetime);
  • filter or sort with a rule that is easier to write than to click.
Run JavaScript Python Return
Once for each item item, $itemIndex input, item_index the new item (an object / dict)
Once for all items items items (and input, the first item) the new list: each element becomes an item
JavaScript Code · Once for all items
const totals = {};
for (const o of items) totals[o.customer] = (totals[o.customer] ?? 0) + o.amount;
return Object.entries(totals).map(([customer, total]) => ({ customer, total }));
Python Code · Once for each item
words = input.get("text", "").split()
{**input, "words": len(words)}
  • JavaScript returns with return; Python passes on the value of its last line (an assignment on the last line returns nothing).
  • Both also get the workflow and the run ($workflow, $execution in JavaScript; workflow, execution in Python).
  • console.log() and print() write to the run’s activity log.
  • Errors name the line and the item: Line 4, item 3: KeyError: 'email'.

Python Code steps saved before AWFlow 0.9 run once per item and return their value under result; see Python Code.

Code runs in an isolated sandbox: no network, no timers or imports, no access to the page or your stored data. JavaScript has a 10-second limit by default (up to 60) and 64 MB of memory (up to 256); Python has a 30-second limit and takes a few seconds to start after a pause. To call an API, use HTTP Request before or after the code step.

The output is null

The last line is an assignment (total = 3) or a statement, so nothing is returned. Put the value on its own as the last line (total).

The Code node ran once per row but you wanted one total

It received a list of items, so it ran for each one. Add Aggregate before it.

input[“title”] raises a KeyError

Several steps are connected, so input is keyed by step label, or the field is missing on this item. Use input.get("title", ""), and check the shape in the previous step’s Output tab.

Ask Aria