Workflows
Blocks
Logic
Script

Script Block

What it does: Run custom code within your workflow to transform data, perform calculations, or implement custom logic.

📜

In simple terms: The Script block is your Swiss Army knife. When you need to do something specific that other blocks can't handle - like complex calculations, data formatting, or custom validations - you can write a small script to do exactly what you need.

When to Use This

Use Script blocks when you need:

  • ✅ Custom data transformations
  • ✅ Complex calculations
  • ✅ Format or restructure data
  • ✅ Validate input in custom ways
  • ✅ Logic not available in other blocks

Example: Calculate a custom discount based on customer loyalty tier and purchase history, then format the result for display.

Key Features

  • Full Programming Power: Write real JavaScript code
  • Access Workflow Data: Use variables from your workflow
  • Return Values: Pass results to other blocks
  • Error Handling: Catch and handle issues gracefully

How Scripts Work

  1. Receive data: Access workflow variables and inputs
  2. Process: Run your custom logic
  3. Return results: Pass values to the next block

Setup Guide

Step 1: Open the Script Editor

Add a Script block to your workflow and click to open the code editor.

Step 2: Write Your Logic

Write your custom code to process the data you need.

Step 3: Return Results

Make sure your script returns the values you need for the next steps of your workflow.

Step 4: Test

Run your workflow to verify the script works correctly.

Common Use Cases

Data Formatting

Convert dates to different formats, format phone numbers, or structure addresses consistently.

Custom Calculations

Calculate taxes, discounts, shipping costs, or any business-specific formulas.

Data Validation

Check if values meet your business rules before proceeding.

String Manipulation

Extract parts of text, combine strings, or clean up user input.

Array Operations

Filter lists, sort data, or aggregate values from collections.

Object Transformation

Restructure data from one format to another for API calls or storage.

Available Data

Within your script, you can access:

  • Workflow variables: Data from previous blocks
  • Input parameters: Values passed to the script
  • Built-in functions: Standard programming utilities

What You Get Back

After the script runs:

  • Return value: Whatever your script returns
  • Success status: Whether the script completed without errors
  • Execution time: How long it took to run

Tips for Success

  1. Keep it simple - Break complex logic into multiple scripts if needed
  2. Handle edge cases - What if a value is empty or unexpected?
  3. Test thoroughly - Try different inputs to catch issues
  4. Add comments - Explain what your code does for future reference
  5. Use descriptive names - Clear variable names make code easier to understand

Troubleshooting

ProblemLikely CauseSolution
Script errorsSyntax or logic issueCheck error message for details
Wrong outputLogic errorDebug by logging intermediate values
Variable not foundTypo or missing dataVerify variable names match exactly
TimeoutScript running too longOptimize code or break into smaller parts
Unexpected nullMissing dataAdd checks for empty values

Best Practices

  • Validate inputs - Check that expected data exists before using it
  • Return clean data - Format output consistently
  • Handle errors - Don't let unexpected values crash your workflow
  • Keep scripts focused - One script, one purpose
  • Document your logic - Comments help future you understand the code
Indite Documentation v1.4.0
PrivacyTermsSupport