Writing Scripts
Write Celigo JavaScript hook scripts -- preSavePage, preMap, postMap, postSubmit, postResponseMap, filter, transform, branching, handleRequest. Use when creating or editing scripts, choosing the right hook point, understanding input/output data shapes, or debugging script behavior.
- Skill ID
- celigo/ai/writing-scripts
- Publisher
- celigo
- Repository
- ai
- Installs
- 0
- Files
- 3
- Synced
- Sep 23, 2026
Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.
celigo/ai/writing-scriptsInstalls these files- SKILL.md
- references/schemas/request.yml
- references/schemas/response.yml
What this skill tells the agent
<!-- TIER:1 -->
Writing Scripts
A script is a JavaScript function that runs at a specific hook point in the Celigo data pipeline. Scripts handle logic that expressions, filters, and visual mappings cannot -- complex conditionals, cross-record calculations, API calls within the pipeline, and custom routing.
Concerns when writing a script:
- Choosing the right hook point -- which function type matches what you're trying to accomplish
- Input/output contracts -- what
optionscontains and what the function must return (array length rules are strict) - Expression alternative -- filter, transform, and output filter have expression-based alternatives that don't require a script; prefer expressions when possible
- Available modules -- scripts can
importthree built-in modules:integrator-api(call Celigo APIs),dayjs(date/time manipulation), andsjcl(Stanford JavaScript Crypto Library for hashing/encryption) - One script, many functions -- a single script resource can contain multiple exported functions, each wired independently to different hook points
Used across flows, APIs, and tools.
Hook Points
Every script function runs at a specific point in the pipeline. Choose based on when you need to act and what data you need access to.
Data Pipeline Hooks
| Hook | Runs on | When | Input | Must return |
|---|---|---|---|---|
preSavePage | Export | After retrieval, before pipeline | options.data[], errors[], files[], retryData{} | { data[], errors[], abort, newErrorsAndRetryData[] } |
preMap | Import | Before field mapping | options.data[] (unmapped records) | Array matching data.length: { data }, { errors }, or {} to skip |
postMap | Import | After field mapping, before submit | options.preMapData[], postMapData[] | Array matching postMapData.length: { data }, { errors }, or {} to skip |
postSubmit | Import | After destination submission | options.preMapData[], postMapData[], responseData[] | responseData[] (same length, modified) |
postAggregate | Import | After file aggregation upload | options.postAggregateData: { success, _json, code, message } | void |
Record-Level Processors (on export or import)
| Hook | When | Input | Must return |
|---|---|---|---|
filter | Per-record, before processing | options.record | boolean (true = process) |
input_filter | Per-record on lookup exports | options.record | boolean (true = include) |
transform | Per-record, reshaping before mapping | options.record | Transformed record |
filter and transform have expression-based alternatives. Only use a script when the logic is too complex for an expression (multi-field conditionals, date math, external lookups).
Flow-Level Hook
| Hook | Runs on | When | Input | Must return |
|---|---|---|---|---|
postResponseMap | Page processor (flow/API/tool) | After response mapping merges results | options.postResponseMapData[], responseData[] | postResponseMapData[] (same length) |
Configured on the flow's pageProcessors[] entry, not on the export/import. Plan this hook when building the resource, but wire it at the flow level.
Routing and Handlers
| Hook | Runs on | When | Input | Must return |
|---|---|---|---|---|
branching | Router | Per-record routing decision | options.record, settings | number[] (branch indices, e.g., [0, 2]) |
handleRequest | API resource | Incoming HTTP request (script-mode API) | options.method, headers, queryString, body, rawBody | { statusCode, headers?, body } |
contentBasedFlowRouter | AS2 connection | EDI message routing | options.httpHeaders, mimeHeaders, rawMessageBody | { _flowId, _exportId } |
Quick Reference
Hook Point Decision Matrix
| When you need to... | Use hook | Configured on | Input / Output |
|---|---|---|---|
| Transform or filter a batch after retrieval | preSavePage | Export | Receives pages of records, returns pages (with optional errors) |
| Filter individual records before processing | filter | Export or import | Receives single record, returns boolean (true = keep) |
| Filter records entering a lookup export | input_filter | Export (lookup) | Receives single record, returns boolean (true = include) |
| Reshape records before mapping | transform | Export or import | Receives single record, returns transformed record |
| Transform records before field mapping | preMap | Import | Receives unmapped records array, returns array (same length) |
| Transform records after field mapping | postMap | Import | Receives pre-map + post-map arrays, returns array (same length) |
| Process API responses after submission | postSubmit | Import | Receives pre-map, post-map, and response arrays, returns response array |
| Handle results after file aggregation | postAggregate | Import (file) | Receives aggregation result, returns void |
| Post-response processing (merge lookup/import results) | postResponseMap | Flow pageProcessors[] entry | Receives merged records + response data, returns merged records (same length) |
| Route records to branches | branching | Router in flow/tool | Receives single record + settings, returns branch indices array |
| Handle incoming HTTP requests (script-mode API) | handleRequest | API resource | Receives method, headers, query, body; returns { statusCode, headers?, body } |
| Route EDI messages to flows | contentBasedFlowRouter | AS2 connection | Receives HTTP/MIME headers + raw body, returns { _flowId, _exportId } |
Minimum Required Fields
A script resource needs only two fields:
name-- descriptive name (convention:<System> - <step> - <hookType>, e.g.,"Salesforce - getBatchRecords - postResponseMap")content-- the JavaScript source code as a string
See references/schemas/request.yml for the full create/update schema.
Related Skills
- configuring-exports > Quick Reference -- export configuration, where
preSavePage,filter,transform, andinput_filterhooks are wired - configuring-imports > Quick Reference -- import configuration, where
preMap,postMap,postSubmit, andpostAggregatehooks are wired - building-flows > How to Build a Flow -- flow construction, where
postResponseMapandbranchinghooks are wired - writing-handlebars > Quick Reference -- Handlebars expressions for dynamic values in scripts and hook configurations
<!-- TIER:2 -->
Common Options Available to All Hooks
Most hooks receive these context fields in options:
_flowId,_integrationId,_apiId,_parentIntegrationId-- execution context IDs_exportIdor_importId-- the step's resource ID_connectionId-- the connection in usesettings-- custom settings in scope for the resourcetestMode-- boolean, whether running in test/preview modejob-- the current job object
Function Point Categories
Scripts run at twelve function points, grouped into four categories. The Hook Points tables above give each one's input/output contract; this is the mental model for which kind of point you're wiring and whether a non-script alternative exists.
- Step-level pipeline hooks (on the export or import) --
preSavePage,preMap,postMap,postSubmit,postAggregate - Parent-level response hook (on the flow/API/tool
pageProcessors[]entry, not the step) --postResponseMap - Script-mode replacements for declarative slots --
filter,input_filter,transform,branching
More from celigo
Use this skill in a project
Open any RiverX project, search the Skills panel for celigo/ai/writing-scripts, and install it in one click.
