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
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 anaction property that matches one of the declared action names:
features array to assign knowledge features to document families:
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.nextActivityIdpoints 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.
triggerKindof the spawned Activity is alwaysACTIVITY_COMPLETED— not script-controllable.
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.
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 callloadDocument(), 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:Navigating the Content 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: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 thetype 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
UseserviceBridge.call(bridgeSlug, endpointName, body?) to make HTTP requests through a bridge:
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
Usellm.invoke(prompt, options?) to send a prompt and get a response:
options parameter accepts:
Using Prompt Templates
If you have prompt templates configured as project resources, usellm.invokeWithPromptRef(promptSlug, parameters?, options?) to resolve and render them:
{variable} placeholders that are replaced with the provided parameter values.
Analyzing Document Content
Combine document loading with LLM calls for AI-powered document analysis: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.*andconsole.*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:- Open the Activity run or parent Task that owns the Activity
- Open the completed SCRIPT step details
- The Logs section displays all log entries with timestamps
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.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’sscript_resultand the new Activity is started only after the current Activity reachesCOMPLETED. Spawn failures are soft — the source Activity still completes and the error is recorded inscript_result.nextActivityError.
