How It Works
When a document is uploaded to an intake:- Metadata is merged (intake config + document metadata + upload params)
- Your script runs with access to filename, content, and metadata
- Based on the script return value, the upload is accepted or rejected
- If accepted, the document family is stored
- Kodexa starts the returned Activity Plan, or the static Activity Plan configured on the intake
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
TheactivityPlan 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:invoice-intake, use Activity Plan steps to decide what human work is needed:
Example: Reject or Route
Validation and Rejection
Returnreject: true to refuse the upload before it is stored:
Metadata Enrichment
Themetadata object is mutable. Any changes are persisted on the document family:
API Response
The upload response returns the created document family object. When an Activity starts successfully, the response also includesactivityId:
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
