Script Processor
Description
The Script Processor component lets you transform data using code you write directly in the scenario. The code is executed on GraalVM polyglot. A single code editor is used, with a language selector. Currently JavaScript and Python are supported.
The value the script returns (via a return statement) is written to the output variable. Its type is inferred
by running the script once when the scenario is validated: objects become records (with typed fields), arrays
become lists, and primitives become their concrete type (Long/Double/String/Boolean). When the type
cannot be determined without a node validation error, the output falls back to Unknown.
Availability
The Script Processor is not available on Nu Cloud. On other installations it appears in the Component Palette only when an administrator has enabled it: the component pulls in GraalVM, so it is opt-in even when its jar is on the model's class path.
To enable it, put components/common/scriptProcessor.jar on the model's classPath and add an entry for the
component provider to the model configuration:
modelConfig {
classPath: [..., "components/common/scriptProcessor.jar"]
components {
scriptProcessor {}
}
}
The same entry holds the limits a script runs within - see Configuration.
Parameters and configuration
| Name | Description |
|---|---|
| Script | The source code to run. Pick the language with the in-editor selector; the editor highlights the chosen language. |
| Output variable name | The name of the output variable that will hold the value returned by the script (type inferred from the script). |
Example
Selecting JavaScript and entering:
return { greeting: "hello", answer: 6 * 7 };
makes the output variable hold a record equivalent to the following JSON:
{
"greeting": "hello",
"answer": 42
}
JavaScript values are converted to plain JVM values: numbers become Long/Double, strings become String,
arrays become List, and objects become Map.
Selecting Python and entering:
return {"greeting": "hello", "answer": 6 * 7}
returns the same shape. Python values are converted to plain JVM values: integers become Long, floats become
Double, strings become String, lists become List, and dictionaries become Map.