Skip to main content
Intake scripts run server-side JavaScript on every document uploaded through an intake endpoint. They execute after metadata is merged but before the document is stored, giving you a chance to inspect the content, enrich metadata, reject invalid uploads, and choose which Activity Plan should run for that upload.

How It Works

When a document is uploaded to an intake:
  1. Metadata is merged (intake config + document metadata + upload params)
  2. Your script runs with access to filename, content, and metadata
  3. Based on the script return value, the upload is accepted or rejected
  4. If accepted, the document family is stored
  5. Kodexa starts the returned Activity Plan, or the static Activity Plan configured on the intake
Scripts run in a sandboxed JavaScript runtime with a 5-second timeout. They cannot make network requests, access the filesystem, or call platform APIs — they operate purely on the data provided to them.

Available Variables

Return Value

The script should return an object. All fields are optional:
If the script returns nothing, the upload proceeds with the original metadata and falls back to the static Activity Plan configured on the intake.

Activity Plans

The activityPlan field lets an intake decide which business process should run for the uploaded document. An intake script starts one Activity. That Activity can then create zero, one, or many Tasks with CREATE_TASK steps. Do not model human review directly in the intake script. The script classifies and routes the upload. The Activity Plan owns the workflow, and Task Templates are referenced inside the Activity Plan when the process needs human work.

Behavior

Activity Start Fields

The uploaded document family is attached to the started Activity automatically. The document family ID is also recorded in the Activity trigger metadata, so your Activity steps can work from the Activity’s document context instead of passing the ID through the script. If an upload should not start work, leave the intake’s static Activity Plan empty or route to a lightweight archival Activity Plan. Scripts should not return an empty Task Template list as the new way to suppress work.

Example: Route by Document Type

Example: Activity Creates the Tasks

The intake script should not return multiple Task Templates. Route to an Activity Plan that contains the task creation logic:
Inside invoice-intake, use Activity Plan steps to decide what human work is needed:

Example: Reject or Route

Validation and Rejection

Return reject: true to refuse the upload before it is stored:
The caller receives an HTTP 400 with the rejection reason:

Metadata Enrichment

The metadata object is mutable. Any changes are persisted on the document family:
Reserved metadata keys (breaking change in 2026.7). Six keys are reserved for the document’s structural fields and cannot be set through the metadata object: uuid, version, labels, mixins, source, and statusId. For example, source holds the document’s original filename.If your script returns a metadata object that contains any of these keys, the intake execution fails and the entire upload is rolled back — no document family is stored. This is a hard execution failure (a server error), not a controlled reject: true rejection. Rename the field to a non-reserved key instead — for example, use metadata.documentSource rather than metadata.source.In earlier releases these keys silently overwrote the structural fields, which could corrupt the stored document. Update any script that writes a reserved key before upgrading.

API Response

The upload response returns the created document family object. When an Activity starts successfully, the response also includes activityId:

Shared Modules

Load reusable JavaScript modules using the Module Refs picker in the Script tab. Selected modules execute before your script, making their functions available in global scope:

Limitations

  • 5-second timeout — scripts that exceed this are terminated and the upload fails
  • No network access — scripts cannot make HTTP requests or call external APIs
  • No filesystem access — scripts operate only on the provided variables
  • Text extraction — only the first 5 pages of PDFs are extracted; other file types may not have text available
  • JavaScript runtime — supports ES5.1 JavaScript with some ES6+ features available