celigo/ai3 files

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.

Specification
Skill ID
celigo/ai/writing-scripts
Publisher
celigo
Repository
ai
Installs
0
Files
3
Synced
Sep 23, 2026
How to use it

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 options contains 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 import three built-in modules: integrator-api (call Celigo APIs), dayjs (date/time manipulation), and sjcl (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

HookRuns onWhenInputMust return
preSavePageExportAfter retrieval, before pipelineoptions.data[], errors[], files[], retryData{}{ data[], errors[], abort, newErrorsAndRetryData[] }
preMapImportBefore field mappingoptions.data[] (unmapped records)Array matching data.length: { data }, { errors }, or {} to skip
postMapImportAfter field mapping, before submitoptions.preMapData[], postMapData[]Array matching postMapData.length: { data }, { errors }, or {} to skip
postSubmitImportAfter destination submissionoptions.preMapData[], postMapData[], responseData[]responseData[] (same length, modified)
postAggregateImportAfter file aggregation uploadoptions.postAggregateData: { success, _json, code, message }void

Record-Level Processors (on export or import)

HookWhenInputMust return
filterPer-record, before processingoptions.recordboolean (true = process)
input_filterPer-record on lookup exportsoptions.recordboolean (true = include)
transformPer-record, reshaping before mappingoptions.recordTransformed 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

HookRuns onWhenInputMust return
postResponseMapPage processor (flow/API/tool)After response mapping merges resultsoptions.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

HookRuns onWhenInputMust return
branchingRouterPer-record routing decisionoptions.record, settingsnumber[] (branch indices, e.g., [0, 2])
handleRequestAPI resourceIncoming HTTP request (script-mode API)options.method, headers, queryString, body, rawBody{ statusCode, headers?, body }
contentBasedFlowRouterAS2 connectionEDI message routingoptions.httpHeaders, mimeHeaders, rawMessageBody{ _flowId, _exportId }

Quick Reference

Hook Point Decision Matrix

When you need to...Use hookConfigured onInput / Output
Transform or filter a batch after retrievalpreSavePageExportReceives pages of records, returns pages (with optional errors)
Filter individual records before processingfilterExport or importReceives single record, returns boolean (true = keep)
Filter records entering a lookup exportinput_filterExport (lookup)Receives single record, returns boolean (true = include)
Reshape records before mappingtransformExport or importReceives single record, returns transformed record
Transform records before field mappingpreMapImportReceives unmapped records array, returns array (same length)
Transform records after field mappingpostMapImportReceives pre-map + post-map arrays, returns array (same length)
Process API responses after submissionpostSubmitImportReceives pre-map, post-map, and response arrays, returns response array
Handle results after file aggregationpostAggregateImport (file)Receives aggregation result, returns void
Post-response processing (merge lookup/import results)postResponseMapFlow pageProcessors[] entryReceives merged records + response data, returns merged records (same length)
Route records to branchesbranchingRouter in flow/toolReceives single record + settings, returns branch indices array
Handle incoming HTTP requests (script-mode API)handleRequestAPI resourceReceives method, headers, query, body; returns { statusCode, headers?, body }
Route EDI messages to flowscontentBasedFlowRouterAS2 connectionReceives 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, and input_filter hooks are wired
  • configuring-imports > Quick Reference -- import configuration, where preMap, postMap, postSubmit, and postAggregate hooks are wired
  • building-flows > How to Build a Flow -- flow construction, where postResponseMap and branching hooks 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
  • _exportId or _importId -- the step's resource ID
  • _connectionId -- the connection in use
  • settings -- custom settings in scope for the resource
  • testMode -- boolean, whether running in test/preview mode
  • job -- 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

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.

Use this skill