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
- Add a Run script action to your workflow.
- The script editor opens with a blank canvas. Write your JavaScript code here.
- Your script can read data from previous steps using the
inputobject (see below). - Use
output.set(key, value)to pass results to subsequent steps. - (Optional) Add npm dependencies in the configuration panel if your script needs external libraries.
- Click Test to run the script with real data from the most recent trigger execution.
- Check the test output and console logs to verify your script works correctly.
- Save the action.
Reading input data
Theinput 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
Writing output
Useoutput.set(key, value) to make data available to subsequent steps. You can set multiple keys.
output.set("status", "success"), the next step can reference status from this script’s output.
Debugging with console.log
During development, useconsole.log() to inspect data and track execution flow. Log output appears in the test panel when you click Test.
npm package management
You can use npm packages in your scripts. Declare dependencies in the configuration panel:require():
Built-in variables
Security: AUTOMATION_TOKEN scope
TheAUTOMATION_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:Complete example: process and route support tickets
Tips
- Start with console.log. When building a new script, log the entire
inputobject 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.
Related
- AI generate — for prompt-based AI tasks that do not need custom code
- HTTP request — for simple API calls that do not need scripting

