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.Documentation Index
Fetch the complete documentation index at: https://developer.kodexa.ai/llms.txt
Use this file to discover all available pages before exploring further.
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
Where Event Scripts Run
Event subscriptions are attached to group data elements in a Data Definition. In configuration, those group elements are stored astaxons. 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
AttacheventSubscriptions 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:
on form when you need to match multiple event types or a custom event pattern.
Fields
Unique name for the subscription within the owning group data element. The runtime uses this name for loop-control state and diagnostics.
Regex pattern matched against the full event string. Kodexa anchors the pattern internally, so
changed:dataAttribute:amount matches only that event string.Convenience field for
changed:dataAttribute. When present with on: "changed:dataAttribute", validation converts it to an on regex and clears dependsOn.JavaScript source executed for the subscription run.
When
true, the subscription remains in the Data Definition but is skipped at runtime.Supported Event Strings
The subscription matcher uses full event strings.| Event string | How it is used |
|---|---|
changed:dataAttribute:field_name | Fired when a data attribute changes. This is the main automatic data-definition event. |
created:dataObject | Fired by the document runtime when a data object is created. |
loaded:dataObject | Fired after initial document load in the browser runtime. |
formLoaded:form_ref | Matches form-load events emitted by the host. |
trigger:name | Matches named events emitted by script or host code. |
focus:dataAttribute:field_name | Matchable event for focus-aware hosts. |
blur:dataAttribute:field_name | Matchable event for blur-aware hosts. |
Runtime Rules
| Rule | Detail |
|---|---|
| Runtime | JavaScript VM |
| Timeout | 2 seconds per subscription execution |
| VM lifetime | Fresh VM per subscription execution |
| Async | No async / await; calls are synchronous |
| Document scope | Use the prebound document; loadDocument() is not supported for subscription scripts |
| Attribute writes | Use currentObject.setAttribute(name, value) |
| Type safety | Typed setters validate against the attribute type |
Execution Order
When a data attribute changes, Kodexa processes the cascade in this order: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.| Global | Available | Use |
|---|---|---|
currentObject | All subscription scripts | The group data object instance that owns the event. May be null; guard before use. |
document | All subscription scripts | The active document containing currentObject. |
event | All subscription scripts | Event payload with the event string, changed attribute, old value, new value, and data object id. |
serviceBridge | Subscription runtimes with platform transport | Calls configured Service Bridges through the platform proxy. |
taxon | Browser subscription runtime | Looks up selection option labels from loaded Data Definitions. |
bridge | Browser subscription runtime | UI/event hooks such as notifications and explicit event firing. Guard before use for cross-runtime scripts. |
log | All subscription scripts | Structured logging with debug, info, warn, and error. |
console | All subscription scripts | Browser-style logging aliases. |
event
The event object describes why the script ran.
| Property | Type | Description |
|---|---|---|
type | string | Full event string, such as changed:dataAttribute:amount |
eventKind | string | Event prefix, such as changed:dataAttribute, when supplied by the host |
attributeTag | string | Changed attribute name for attribute events |
attributePath | string | Full attribute path when available |
dataObjectId | number | ID of the data object where the event occurred |
oldValue | any | Typed value before the change |
newValue | any | Typed value after the change |
formName | string | Form reference for formLoaded:* events |
triggerName | string | Trigger name for trigger:* events |
currentObject
currentObject is the data object instance for the group data element where the event matched.
Reading Values
| Method | Returns | Use |
|---|---|---|
getPath() | string | Data object definition path |
getIDString() | string | Data object ID as a string |
getParent() | DataObject or null | Parent data object |
getChildren() | DataObject[] | Child objects already attached to this object |
getChildrenByPath(path) | DataObject[] | Direct children matching a path |
getAttributeByName(name) | DataAttribute or null | First matching attribute wrapper |
getAttributesByName(name) | DataAttribute[] | All matching attribute wrappers |
getFirstAttributeValue(name) | string, number, boolean, string date, or undefined | First typed attribute value |
getAttributeValues(name) | string[] | All matching values stringified |
hasTaxonomy() | boolean | Whether the object has a Data Definition reference |
Writing Values
UsesetAttribute(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.
Payloads For Service Bridges
payload(mapping) builds a plain JavaScript object from attributes on currentObject.
Creating Child Data Objects
UsegetOrCreateChild(path, opts?) or addChild(opts) when the event should create modeled child data.
copyAttributesFrom(sourceObj, mappings, ownerUri?) when moving known attributes between objects:
DataAttribute
getAttributeByName() and getAttributesByName() return attribute wrappers for lower-level operations.
| Method | Use |
|---|---|
getTag() | Attribute tag/name |
getPath() | Full attribute path |
getOwnerUri() | Audit owner URI |
getValue() | Raw value |
getStringValue() | Typed string value |
getDecimalValue() | Typed numeric value |
getBooleanValue() | Typed boolean value |
getDateValue() | Typed date value as RFC 3339 |
getConfidence() | Confidence value, or 0 when absent |
getDataFeatures() | Attribute data features |
setStringValue(value) | Persist typed string value |
setDecimalValue(value) | Persist typed numeric value |
setBooleanValue(value) | Persist typed boolean value |
setDateValue(value) | Persist typed date value from RFC 3339 string |
setConfidence(value) | Persist confidence |
addFeature(key, value) | Add a data feature |
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
| Method | Use |
|---|---|
getAllDataObjects() | Return all data objects |
findDataObjectsByPath(path) | Return all objects for a path |
findFirstDataObjectByPath(path) | Return the first object for a path |
getOrCreate(path, opts?) | Find or create a top-level data object |
createDataObject(opts) | Create a data object |
deleteDataObject(id) | Delete a data object |
copyDataObject(opts) | Copy a data object |
moveDataObject(opts) | Move a data object |
batchCopyDataObjects(opts[]) | Copy several objects atomically |
batchMoveDataObjects(opts[]) | Move several objects atomically |
updateDataObject(obj) | Persist in-memory object changes |
getDataObjectsByParentId(parentId) | Return direct children for a parent ID |
Document Metadata And External Data
| Method | Use |
|---|---|
getUUID() / getVersion() | Document identity |
getLabels() / addLabel(label) / removeLabel(label) | Document labels |
getMetadata() / setMetadata(key, value) | Document metadata map |
getDocumentMetadataMap() | Copy of document metadata |
getDocumentMetadataValue(key) | Single document metadata value |
setDocumentMetadataValue(key, value) | Set or delete document metadata value |
getExternalData(key) | External data entry |
setExternalData(key, data) | Write external data |
getExternalDataKeys() | External data keys |
Content, Search, And Serialization
| Method | Use |
|---|---|
getRootNode() / getContentNode() | Access the document content tree |
select(selector, variables) | Select content nodes |
selectFirst(selector, variables) | Select the first matching node |
getAllTags() | Unique document tags |
searchContent(pattern, opts) | Regex content search |
searchLines(query, opts) | Line search |
getSearchableLines() | Searchable line records |
toJSON() | Serialize document metadata and data objects |
dataObjectsToJSON() | Serialize data objects only |
Exceptions And Validations
| Method | Use |
|---|---|
createDataException(opts) | Create a data exception |
updateDataException(opts) | Update a data exception |
closeDataException(id, comment) | Close a data exception |
reopenDataException(id) | Reopen a data exception |
getAllDataExceptions() | All data exceptions |
getOpenDataExceptions() | Open data exceptions |
getDataExceptionById(id) | One data exception |
getDataExceptionsByDataObjectId(id) | Exceptions for a data object |
addValidation(opts) | Add validation metadata |
getValidations() / setValidations(opts) | Read or replace validations |
validateDocument() | Run document validation |
serviceBridge
serviceBridge.call(bridgeRef, endpointName, body?) calls an external system through a configured Service Bridge.
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.
bridge
The browser subscription runtime exposes bridge for UI notifications and explicit event emission.
| Method | Use |
|---|---|
bridge.notify(title, message, severity?) | Show a user notification. Severity defaults to info. |
bridge.events.fire(eventString, dataObjectId?) | Emit another event into the recalculation cascade. |
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:| Guard | Behavior |
|---|---|
| Active frame guard | A subscription cannot re-enter itself while already running for the same data object. |
| Cascade deduplication | A subscription runs at most once per data object in one user-driven cascade. |
| Maximum depth | Nested event execution is capped at 8 levels. |
| No-op suppression | Writes that do not change typed values are suppressed. |
Examples
Normalize And Derive Sibling Values
Service Bridge Enrichment
Create A Data Exception
Emit A Follow-Up Event
Constraints
Best Practices
Start with the event string
Start with the event string
Name the exact business event the script responds to. Prefer specific
on patterns such as changed:dataAttribute:(quantity|unit_price) over broad matches.Keep the script local to the group
Keep the script local to the group
Read and write values on
currentObject when possible. Use document only when the script really needs broader document context.Make writes idempotent
Make writes idempotent
Write the same result for the same inputs. Avoid appending duplicate child objects or recreating exceptions without checking existing state.
Use typed values
Use typed values
getFirstAttributeValue returns typed values. Preserve those types when writing with setAttribute.Guard browser-only helpers
Guard browser-only helpers
Wrap
bridge and the taxon helper usage in typeof ... !== "undefined" checks when a script may also run outside the browser runtime.Log the decision, not every value
Log the decision, not every value
Use
log.debug while building and keep production logs focused on decisions, external calls, and unexpected states.Related
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
