Skip to main content
Event-based scripting belongs to Data Definitions. It is how the data model reacts when values change. A Data Form renders the review experience for a Task. A Data Definition owns the structure and behavior of the business data being reviewed. Event subscriptions let that data model run JavaScript when an event occurs, such as an attribute changing on a data object. Use event scripts when a change to one field should update other fields, call an external system, create an exception, emit another event, or apply business logic that is too procedural for a formula.

When To Use Event Scripts

Use an event subscription when the data definition needs behavior, not just structure:
  • Derive several sibling attributes after a reviewer edits one value
  • Normalize data before formulas, validation, and selection rules run
  • Call a Service Bridge to enrich a row from an external system
  • Create or close data exceptions based on business logic
  • Copy or move data objects when a modeled relationship changes
  • Emit a named event that another subscription can handle
Use a formula when one output value can be computed declaratively from other values. Use event scripting when the change has side effects or needs multiple reads and writes.

Where Event Scripts Run

Event subscriptions are attached to group data elements in a Data Definition. In configuration, those group elements are stored as taxons. At runtime, the script executes for one data object instance of that group. The script runs inside the recalculation flow. Writes made by the script are visible to downstream formula recalculation, selection option evaluation, validation, selection validation, and conditional formatting.

Configuration

Attach eventSubscriptions to a group data element:

Attribute Change Shorthand

For simple attribute-change subscriptions, dependsOn is a compact way to list the attributes that should trigger the script:
Kodexa expands that into the equivalent event pattern:
Use the explicit on form when you need to match multiple event types or a custom event pattern.

Fields

string
required
Unique name for the subscription within the owning group data element. The runtime uses this name for loop-control state and diagnostics.
string
required
Regex pattern matched against the full event string. Kodexa anchors the pattern internally, so changed:dataAttribute:amount matches only that event string.
string[]
Convenience field for changed:dataAttribute. When present with on: "changed:dataAttribute", validation converts it to an on regex and clears dependsOn.
string
required
JavaScript source executed for the subscription run.
boolean
default:"false"
When true, the subscription remains in the Data Definition but is skipped at runtime.

Supported Event Strings

The subscription matcher uses full event strings.
changed:dataAttribute fires when an attribute first receives a value, not only on later edits. Setting a value on a previously blank field is treated as a change, so a reviewer’s first pick into an empty field runs the matching subscription just as a subsequent edit would.
For common attribute-change subscriptions, use:
For a named event:
For multiple event types:

Runtime Rules

Execution Order

When a data attribute changes, Kodexa processes the cascade in this order:
This ordering matters. If an event script writes tax_rate, formulas and validations that depend on tax_rate see the value written by the script.

Script Globals

Every event subscription receives a small set of prebound globals.

event

The event object describes why the script ran. Example:

currentObject

currentObject is the data object instance for the group data element where the event matched.

Reading Values

Writing Values

Use setAttribute(name, value) for normal writes. It finds or creates the attribute, resolves the target type from the Data Definition when available, writes the typed value, persists the change, and notifies the recalculation system.
Supported value types are strings, numbers, booleans, and RFC 3339 date strings for date attributes.
Type mismatches fail the script. For example, writing "abc" to a numeric data element raises a JavaScript error from the typed setter.

Payloads For Service Bridges

payload(mapping) builds a plain JavaScript object from attributes on currentObject.
Missing attributes are returned as empty strings. This keeps Service Bridge request bodies stable.

Creating Child Data Objects

Use getOrCreateChild(path, opts?) or addChild(opts) when the event should create modeled child data.
Use copyAttributesFrom(sourceObj, mappings, ownerUri?) when moving known attributes between objects:

DataAttribute

getAttributeByName() and getAttributesByName() return attribute wrappers for lower-level operations. Prefer currentObject.setAttribute(...) for common writes. Use DataAttribute methods only when you need direct access to a specific attribute instance.

document

The document global is the active KDDB document.

Data Object Access

Document Metadata And External Data

Content, Search, And Serialization

Exceptions And Validations

Example:

serviceBridge

serviceBridge.call(bridgeRef, endpointName, body?) calls an external system through a configured Service Bridge.
Bridge refs may be fully qualified as orgSlug/bridgeSlug. Some runtimes can supply a default organization slug, but fully qualifying the bridge keeps scripts portable. The bridge response is parsed as JSON. If the platform proxy returns a result envelope, the runtime returns the result value directly. If the proxy returns an error envelope, the script fails with that error.

taxon

In the browser subscription runtime, taxon.optionLabel(taxonName, value) returns the display label for a selection option value.
Guard this helper if the same script may run in a runtime that has not loaded Data Definition bindings:

bridge

The browser subscription runtime exposes bridge for UI notifications and explicit event emission.
Fire a follow-up event when another subscription should respond:
Only emit events deliberately. Emitted events participate in the same loop-control rules as automatic events.

Logging

Use structured logging during development and troubleshooting:
console.log, console.warn, and console.error are also available.

Loop Control

The recalculation service protects event scripts from runaway cascades: Design scripts to be idempotent. A script may run more than once over the life of a document, and retries should not duplicate data or re-open resolved work.

Examples

Normalize And Derive Sibling Values

Service Bridge Enrichment

Create A Data Exception

Emit A Follow-Up Event

Constraints

Event subscriptions can only be declared on group data elements.
Scripts run synchronously with a 2-second timeout. Keep external calls bounded and avoid large document scans.
Subscription scripts are scoped to the active document. Use the prebound document global; do not call loadDocument().

Best Practices

Name the exact business event the script responds to. Prefer specific on patterns such as changed:dataAttribute:(quantity|unit_price) over broad matches.
Read and write values on currentObject when possible. Use document only when the script really needs broader document context.
Write the same result for the same inputs. Avoid appending duplicate child objects or recreating exceptions without checking existing state.
getFirstAttributeValue returns typed values. Preserve those types when writing with setAttribute.
Wrap bridge and the taxon helper usage in typeof ... !== "undefined" checks when a script may also run outside the browser runtime.
Use log.debug while building and keep production logs focused on decisions, external calls, and unexpected states.

Data Definitions

Define the data model that event scripts operate on

Data Definition Structure

Configure data elements, groups, validations, selection options, and event subscriptions

Selection Option Formulas

Compute dynamic selection options from data and bridge calls

Service Bridges

Configure external API calls used by event scripts