This page provides copy-and-paste JavaScript examples for common automation tasks. Each script is designed to work in the Script action’s sandbox environment, using input to read data from previous steps and output.set() to pass results forward.
Call an external API
When to use: You need to fetch data from a third-party service — weather data, exchange rates, a lookup service, or any REST API.
Call the Teable API
When to use: You need to interact with Teable data in ways that go beyond the built-in Get Records, Create Record, and Update Record actions — for example, batch operations or reading table metadata.
Batch create records via Teable API
When to use: You need to create many records at once and want to do it in a single API call instead of looping with the Create Record action. This is faster for large batches.
When to use: You need to reshape or extract specific fields from records before passing them to the next step — for example, creating a simplified summary array.
Filter records by condition
When to use: You have an array of records and need to narrow it down based on custom logic that is more complex than what the built-in filter builder supports — for example, date comparisons, multi-field conditions, or calculations.
When to use: You receive a JSON string from a webhook, an API response, or a text field, and need to extract or restructure the data.
When to use: You need to calculate due dates, format dates for display, find the difference between dates, or check if a date falls within a range.
Conditional processing
When to use: You need to apply different logic based on the data — routing records to different categories, applying different calculations, or choosing different actions based on field values.
Send a Slack message
When to use: You want to send a formatted notification to a Slack channel as part of your automation. This gives you more control over formatting than the HTTP Request action.
Aggregate and summarize records
When to use: You have an array of records and need to compute totals, averages, counts by category, or other aggregate statistics.
Tips for all scripts
- Always handle errors. Wrap API calls and JSON parsing in try/catch blocks.
- Log during development. Use
console.log() to inspect data structures. Logs appear in the test panel.
- Keep scripts under 60 seconds. The sandbox enforces a timeout. For large datasets, process in batches.
- Use
output.set() for every value you need in later steps. Data not set via output.set() is not accessible to subsequent actions.
- Test with real data. Click the Test button to run your script against actual automation data.
- Run script guide — full reference for the scripting environment
- HTTP request — for simple API calls without scripting
- Loop (batch) — for iterating without code
Last modified on May 26, 2026