Skip to main content
This page is the runtime reference for SCRIPT steps inside Activity Plans. Use it when you need the exact JavaScript objects, helper methods, and limits available while an Activity is running custom logic.

Overview

A script step runs inline JavaScript in a sandboxed runtime. It has access to:
  • The current task and its properties
  • Document families attached to the task
  • The ability to load KDDB documents and inspect or modify their content
  • Knowledge feature lookups for classification workflows
  • Logging for diagnostics
  • Service bridge calls to external APIs (project-scoped)
  • LLM invocations with automatic cost tracking
Scripts return an action that determines which downstream path the Activity follows.

Adding a Script Step

1

Open the Activity Plan

Open the Activity Plan that models the business workflow.
2

Add a SCRIPT Step

Add a SCRIPT step to the Activity Plan graph.
3

Place It in the Flow

Connect dependencies from upstream steps, then connect action outcomes to downstream steps.
4

Write Your Script

Select the script step and write JavaScript in the editor. Use the full-screen editor and snippets for larger scripts.
5

Define Actions

Add one or more actions in the Script Actions section. These are the possible outcomes your script can return.
6

Connect Dependencies

Use dependencies such as route:review or route:post so downstream steps only run for the matching action.

Script Structure

Every script must return an object with an action property that matches one of the declared action names:
Optionally, the return value can include a features array to assign knowledge features to document families:
The return value can also include a nextActivity block to spawn a follow-up Activity Plan when the current Activity completes. Use this to chain related workflows — for example, kicking off an extraction plan from an intake script.
nextActivity accepts the following fields: Semantics:
  • Deferred spawn: the new Activity starts only after the current Activity reaches COMPLETED, not at the moment the script returns.
  • Same-project only: cross-project spawns are rejected.
  • Soft fail: spawn failures (target plan missing, FGAC denial, input validation failures) leave the source Activity completed and record the error in script_result.nextActivityError. On success, script_result.nextActivityId points to the new Activity.
  • One per script return; multiple SCRIPT steps in the same plan may each emit their own and they fan out at completion.
  • triggerKind of the spawned Activity is always ACTIVITY_COMPLETED — not script-controllable.
See Spawning a Follow-Up Activity for the chaining pattern.

Context Objects

Scripts have access to several pre-bound context objects. These are available as global variables in your script. The Activity Plan runtime is Task-centered. If an Activity was started from a Task, scripts receive the Task snapshot and document families attached to it. The runtime does not expose arbitrary browser state; scripts work through the bound Task, document family, document, Service Bridge, LLM, and knowledge helper objects.

task

The current task being processed.

families

An array of document families attached to the task. Each content object has:

org

The current organization.

inputs

The Activity’s materialized inputs as a plain key/value object. This is the same input values that BRIDGE_CALL requestBody JSONata templates resolve against — exposed here as a global variable so script steps can read them too. inputs always defaults to an empty object ({}) when the Activity has no inputs, so you can read inputs.someField directly without a typeof / undefined guard. It is a read-only snapshot — assigning to it does not change the Activity’s stored inputs.
This inputs runtime global is distinct from the nextActivity.inputs spawn field shown earlier. inputs is what the current Activity received; nextActivity.inputs is the payload you pass to a follow-up Activity you spawn.

Complete Runtime Objects

Global Helpers

tasks

The tasks namespace reads and updates Task records in the same project as the current Activity. Task objects returned from tasks include id, title, description, status, statusType, statusLabel, metadata, data, parentTaskId, templateId, assigneeId, teamId, priority, locked, createdOn, and updatedOn.

documents

The documents namespace reads and updates document family records in the current project. Use it for family-level state. Use loadDocument() when you need content nodes, tags, data objects, validations, exceptions, or KDDB metadata. Document family summaries include id, path, summary, metadata, labels, mixins, features, featureIds, status, statusLabel, locked, pendingProcessing, storeSlug, storeRef, contentObjects, createdOn, and updatedOn.

Helper Functions

log.{debug,info,warn,error}(...args)

Write a log entry via leveled methods. Each method is variadic and joins arguments with spaces.

loadDocument(familyId)

Load a KDDB document by its family ID. Returns a document object with methods for reading and modifying content. Limited to 5 calls per script execution.
Do not call doc.close() in your scripts. The orchestrator automatically persists any document modifications as new content object versions after the script completes. Calling close() prematurely closes the underlying database, which prevents the orchestrator from saving your changes.

lookupFeature(slug)

Look up a single knowledge feature by its slug. Returns the feature object or null.

lookupFeatureType(slug)

Look up a knowledge feature type by its slug. Returns { id, name, slug } or null.

lookupFeaturesByType(typeSlug)

Get all knowledge features belonging to a feature type. Returns an array of { id, slug } objects.

lookupFeatureByProperties(featureTypeSlug, properties)

Find a feature by the deterministic slug generated from its feature type and properties.

lookupOrCreateFeature(featureTypeSlug, properties)

Find or create a feature using the deterministic slug generated from the feature type and properties.

Working with Documents

When you call loadDocument(), you receive a document object with both read and write capabilities.

Reading Document Content

Selecting Content Nodes

Use selector expressions to find specific content nodes in the document tree:
Content nodes form a tree structure (document > page > line > word). You can navigate it programmatically:

Content Node Properties

Each content node provides:

Modifying Documents

Script steps can modify documents. Changes are automatically persisted as new content object versions after the script completes.

Setting Metadata and Labels

Tagging Content Nodes

Tags mark content nodes for downstream processing or data extraction:
Tag options:

Adding Features to Content Nodes

Creating Data Objects

Data objects represent structured, extracted data:

Nested Data Objects

Build hierarchical data structures with parent/child relationships:

Reading Data Objects

Attribute Data Types

When adding attributes, specify the type to control how the value is stored and displayed:

Knowledge Feature Assignment

Scripts can assign knowledge features to document families as part of their return value. This is useful for classification workflows where the script analyzes document content and assigns the appropriate features.

Calling Service Bridges

Script steps can call external APIs through service bridges that are configured as project resources. Only bridges that have been added to the task’s project are accessible — scripts cannot call arbitrary bridges in the organization.

Calling an Endpoint

Use serviceBridge.call(bridgeSlug, endpointName, body?) to make HTTP requests through a bridge:
The response is automatically parsed as JSON if possible, otherwise returned as a string. Limited to 10 calls per script execution with a 10-second timeout per call. Use serviceBridge.list() when you need to inspect the project-scoped bridges available to the script:

Example: Enriching Documents via External API

Service bridges must be added as project resources before they can be used in script steps. If a bridge exists in the organization but is not linked to the project, scripts will receive a “bridge not found” error.

Making LLM Calls

Script steps can invoke the platform’s LLM (Large Language Model) service directly. All calls are automatically tracked in model costs for billing and reporting.

Basic LLM Call

Use llm.invoke(prompt, options?) to send a prompt and get a response:
The optional options parameter accepts:

Using Prompt Templates

If you have prompt templates configured as project resources, use llm.invokeWithPromptRef(promptSlug, parameters?, options?) to resolve and render them:
Prompt templates support {variable} placeholders that are replaced with the provided parameter values.

Analyzing Document Content

Combine document loading with LLM calls for AI-powered document analysis:
LLM calls are limited to 5 per script execution and count against your organization’s model costs. Each call records the input and output token counts in the platform’s billing system.If the LLM service is not configured on your environment, calls will throw an error with a clear message.

Full Workflow Example

This example combines document inspection, tagging, data extraction, and knowledge feature assignment into a single script:

The Script Editor

The plan flow editor provides two ways to edit script code:

Inline Editor

When you select a script node, the properties panel on the right shows a Monaco code editor with:
  • Syntax highlighting for JavaScript
  • IntelliSense auto-completion for all context objects, helper functions, and document APIs
  • Script Actions management below the editor

Full-Screen Editor

Click the Expand button to open the full-screen script editor, which provides:
  • A large code editing area
  • A Snippet Browser panel on the right with categorized code templates
  • Insert or Replace buttons to use snippets as starting points
  • Script action management in the footer

Snippet Categories

The snippet browser includes ready-to-use templates organized by category:

Viewing Script Logs

Script step logs are captured in CloudWatch and viewable from the Activity step details.

How It Works

Every script execution automatically records:
  • A start log entry when the script begins
  • All log.* and console.* calls made during execution
  • An end log entry when the script completes (with success or error status)

Viewing Logs in the UI

To view logs for a completed script step:
  1. Open the Activity run or parent Task that owns the Activity
  2. Open the completed SCRIPT step details
  3. The Logs section displays all log entries with timestamps
Logs are paginated for scripts that produce large amounts of output. Use the search field to filter log entries by message content.
Add log.info(...) calls at key decision points in your scripts. The logs persist after execution, making them invaluable for debugging routing decisions and understanding why a script chose a particular action.

Loading Shared Modules

Script steps can pre-load reusable JavaScript modules so that their functions and variables are available in global scope within your script. This lets you build a library of shared utilities, such as string helpers, validation logic, and API wrappers, and reuse them across multiple script steps without duplicating code. To configure module pre-loading, use the Module Refs picker in the script step’s properties panel. Select one or more JavaScript modules from your organization. The selected modules are fetched and executed in order before your script runs.
Shared modules must be JavaScript modules deployed with scriptLanguage: "javascript" and an inline script field. A maximum of 10 modules can be pre-loaded per script step.

Execution Details

  • Runtime: JavaScript (ES5+) via the Goja engine
  • Timeout: 15 seconds per script execution (all operations, including document loads, bridge calls, and LLM calls, count against this limit)
  • Document loads: Maximum 5 per script execution
  • Service bridge calls: Maximum 10 per script execution, 10-second timeout per call, project-scoped
  • LLM calls: Maximum 5 per script execution, token usage recorded in model costs
  • Persistence: Any document modifications (tags, metadata, labels, data objects) are automatically saved as new content object versions after the script completes. Do not call doc.close() yourself.
  • Action matching: The returned action name is matched case-insensitively against the declared script actions
  • Spawned activities: When a script returns nextActivity, the spec is recorded onto the source step’s script_result and the new Activity is started only after the current Activity reaches COMPLETED. Spawn failures are soft — the source Activity still completes and the error is recorded in script_result.nextActivityError.