Skip to main content
We strongly recommend using Run script to build automations, because it can cover all action behaviors, including actions that would otherwise need to be built manually. Just describe your requirements to AI in chat.Please note: if you add actions manually, AI will not recognize or modify them later.
The Run script action lets you write custom JavaScript to handle logic that built-in actions cannot cover. You can transform data, call external APIs, perform calculations, implement conditional branching, and more — all within a secure sandbox environment. Scripts receive data from previous steps via the input object and pass results to subsequent steps via the output.set() function.

When to use Run script vs. built-in actions

In general, use built-in actions when they fit your needs. Use Run script when you need custom logic, data transformation, or complex API interaction.

Environment

How to set it up

  1. Add a Run script action to your workflow.
  2. The script editor opens with a blank canvas. Write your JavaScript code here.
  3. Your script can read data from previous steps using the input object (see below).
  4. Use output.set(key, value) to pass results to subsequent steps.
  5. (Optional) Add npm dependencies in the configuration panel if your script needs external libraries.
  6. Click Test to run the script with real data from the most recent trigger execution.
  7. Check the test output and console logs to verify your script works correctly.
  8. Save the action.

Reading input data

The input object contains data from all previous steps in the workflow. Each step is identified by its action ID.

Input structure

Getting trigger data (record fields)

Getting data from a Get Records step

Getting data from other action outputs

Use console.log(JSON.stringify(input, null, 2)) during testing to see the exact structure of your input data. This is the fastest way to understand what is available.

Writing output

Use output.set(key, value) to make data available to subsequent steps. You can set multiple keys.
Each key you set becomes a separate variable that subsequent steps can reference via the + variable picker. For example, if you call output.set("status", "success"), the next step can reference status from this script’s output.

Debugging with console.log

During development, use console.log() to inspect data and track execution flow. Log output appears in the test panel when you click Test.
Console logs are only visible during testing — they do not appear in production run history. Use them liberally while building your script.

npm package management

You can use npm packages in your scripts. Declare dependencies in the configuration panel:
Then use them in your script with require():
Prefer built-in JavaScript features over npm packages when possible. Modern JavaScript has many utilities built in — Array.map(), Array.filter(), Object.entries(), template literals, destructuring, etc. Only add npm packages when they provide significant value.

Built-in variables

Security: AUTOMATION_TOKEN scope

The AUTOMATION_TOKEN is automatically generated for each automation run. It has the same permissions as the automation creator and is scoped to the current execution. Key points:
  • It can access any table the automation creator has access to.
  • It is valid only for the duration of the script execution (60-second timeout).
  • Do not expose this token to external systems — it is meant for calling the Teable API from within your script.

Calling the Teable API

Calling AI from a script

POST /api/automation/runtime/ai sends a prompt to your base’s AI model. The base comes from the automation’s context, so no base ID is needed. The body takes prompt, plus optional attachments, modelKey, temperature, and outputType; the response is { "message": ... }. Attachments are { url, mimetype, name } items, up to 10 per call, each under 20MB and 30 seconds to download, covering images, PDFs, and Office documents. The default chat model may not read images and similar attachments, so pass modelKey when you send files. Each call consumes credits.

Error handling

Always wrap risky operations in try/catch blocks so your workflow can handle failures gracefully:
Without error handling, a failed fetch or unexpected data format will crash the script, and subsequent steps will not receive any output.

Complete example: process and route support tickets

Tips

  • Start with console.log. When building a new script, log the entire input object first to understand its structure.
  • Keep scripts focused. Do one thing well rather than cramming multiple tasks into one script. Chain multiple Run script actions if needed.
  • Mind the 60-second timeout. Long-running operations (large data processing, many sequential API calls) can hit the timeout. Break large tasks into smaller chunks.
  • Test with real data. The test panel uses actual data from the most recent trigger execution, giving you realistic results.
  • Handle missing data. Use default values (|| operator) for fields that might be empty or undefined.
  • AI generate — for prompt-based AI tasks that do not need custom code
  • HTTP request — for simple API calls that do not need scripting
Last modified on August 7, 2026