CompanionCompanion
Companion for Delivery
Companion for Business
Companion for Integration
Contact us
Companion for Delivery
Companion for Business
Companion for Integration
Contact us
  • Companion for Integration

    • Introduction
    • Getting Started
    • Configuration
    • Excel templating
    • How it works
  • YAML Configuration

    • Principles
    • Syntax
    • Validation
  • Custom Functions

    • Summary
    • arrayToJSON
    • bool
    • concatValueAndUnit
    • convertUnit
    • currentContextId
    • exportTime
    • eval
    • firstNonEmpty
    • getContextName
    • getEvents
    • getLastEventTime
    • getReferencesByAttributeGroup
    • getStoredValue
    • getWorkspaceId
    • hash
    • hasStoreKey
    • if
    • integer
    • join
    • mergeInheritedValues
    • multiValuesToJSON
    • number
    • nodeList
    • order
    • resolveUnitLabel
    • serializeAssetPushLocationsToJSON
    • serializeAttributeLinksToJSON
    • serializeContextReferenceToJSON
    • serializeContextReferencesToJSON
    • serializeContextValuesToJSON
    • serializeDataContainerToJSON
    • serializeDataContainersToJSON
    • serializeListOfValueValuesToJSON
    • serializeReferencesToJSON
    • serializeReferenceToJSON
    • serializeValuesToJSON
    • store
    • toXML
    • uppercase
  • Execution

    • Summary
    • Composite
    • From STEP
    • Standalone
    • Performance statistics
  • Configuration

    • ActiveMQ extension
    • Amazon AWS extension (SNS, SQS, Kinesis, S3)
    • ElasticSearch/OpenSearch extension
    • File extension (Excel, CSV, JSON, XML, JSONL, XMLL)
    • Kafka extension
    • Kafka Core extension
    • MongoDB/Cosmos DB extension
    • SQL extension
    • REST extension
    • Google Pub/Sub extension
  • c4i SaaS

    • Introduction
    • Managing jobs
    • Managing executions
    • Managing users
    • Changelog
  • Changelog

    • Core features changelog
    • ActiveMQ extension changelog
    • Amazon AWS extension changelog
    • Composite extension changelog
    • ElasticSearch extension changelog
    • File extension changelog
    • Kafka extension changelog
    • Kafka Core extension changelog
    • MongoDB/Cosmos DB extension changelog
    • SQL extension changelog
    • REST extension changelog
    • Google Pub/Sub extension changelog

eval

The eval function is used evaluate Javascript scripts

Keep in mind that Javascript scripts are not STEP Business Rules. There is no access to STEP API function such as Managers, Nodes, ...

Syntax

c4i:eval(scriptId, [params]])

Parameters

scriptId

  • STEP execution : The ID of the asset containing the JS script
  • Standalone execution : The path to the JS script

params (optional)

Script parameters. The parameters are available through bindings named $1, $2, ...

See examples below

Return value

The result of the script execution. Javascript objects will be converted to JSON objects

Context

A binding named context is available during script execution.

The following methods are available on the context binding :

  • store(key, value) : Store a key-value pair the same way as the store does
  • storeJson(key, value): Store a JS object as JSON
  • getStoredValue(key): Gets a stored value from a key
  • getCurrentContextId(): Returns the current context ID. See currentContextId
  • getExportTime(): Returns the current export time. See exportTime

Control execution order using the order custom function.

Parameters

Any XPath, executed against the currently mapped node, can be used as a parameter for script evaluation.

Some important remarks :

  • XPath functions such as string provide String objects
  • Otherwise, general XPath evaluation provide instances of NodeList

Return values

Unlike STEP Business Conditions, JS scripts do not need to explicitly return a value. The script evaluation is its return value.

For example, if you want to return a String value, the script should be :

"Example return value";

And not :

return "Example return value";

Auto-complete

By adding the following dependency to your classpath : fr.cantor.c4i:js-helpers, your IDE can provide you with auto-complete and documentation for :

  • Standard Java DOM API
  • Structures returned by C4i custom functions

Example

Simple example without parameters:

The following example illustrates how to return a String value :

String parameter example

The following example illustrates how to manipulate a provided String parameter

Manipulate a NodeList returned by XPath evaluation and return JSON data

The following example illustrates how to manipulate a NodeList returned by XPath evaluation and return JSON data

Store JSON data

The following example illustrates how to return JSON data and how to reuse it later using the json custom function.

In this example, the .family mapping rule is evaluated but its output is ignored. This is why we can return null in the JS script after storing the JSON value.

The order function is used to make sure that the .family mapping rule is executed before the product mapping rule.

Last Updated: 4/13/26, 10:42 AM
Prev
exportTime
Next
firstNonEmpty