JavaScript Documentation
Version: 1.0.0
Retrieved: 2025-10-09 15:15:58
JavaScript
Use JavaScript to transform the incoming message.
A very flexible module that allows you to edit the flow message that arrives into the module. Perfect for doing simple things not covered by other modules. You can also do more complex formatting that normally would require a custom module.
For more information, see github.com/sebastienros/jint
Settings
| Name | Requirements | Purpose | Default |
|---|---|---|---|
| Script | String 0 to 8192 in length | The JavaScript code to run when a message arrives | `` |
Important information about removing/deleting properties/objects
The msg sent into the module and used in JavaScript is a regular FlowMessage. You can't remove properties or objects from the msg with JavaScript code. Instead you have to use methods on the FlowMessage class to do this.
Let´s say we have a msg looking like {person: {name: 'steve', age: 43}} and we want to remove the age property from the person object.
msg.Remove('person.age');
Now the msg will look like {person: {name: 'steve'}} and you have to use the Remove method to do this.
Examples
You will be able to alter the message with JavaScript code, it may be anything from adding a new object to altering the complete structure by using JavaScript functions.
Note: There is no need to return anything at the end of the script, you are altering the actual message as a reference inside the script.
You will access the message with the msg property.
Add Extra Properties
# Settings:
Script = "
msg.person.age = 33;
msg.person.skills = ["CSharp", "Rust", "JavaScript"];
"
# Incoming message
{
"person": {
"name": "steve"
}
}
# Outgoing message:
{
"person": {
"name": "steve",
"age": 33,
"skills": ["CSharp", "Rust", "JavaScript"]
}
}
Clear & Create a New Message
This will remove all properties on the msg and then add a new object with a different structure
# Settings:
Script = "
msg.Clear();
msg.people = [
{name: "steve"},
{name: "molly"}
];
"
# Incoming message
{
"car": {
"brand": "Volvo",
"model": "XC90",
"color": "red"
}
}
# Outgoing message:
{
"people": [
{"name": "steve"},
{"name": "molly"}
]
}
Using JavaScript functions
Showing that you can alter the structure by calling JavaScript functions. In this case we alter the layout of the objects to be able to use them with another module.
We have car information as a plain string array ['Chevrolet','Camaro','yellow']. Now we want to transform the array to insert the information into a database.
# Settings:
Script = "
msg.car = msg.data.reduce(function (acc, value, i) {
var colName = "";
switch(i){
case 0:
colName = "brand";
break;
case 1:
colName = "model";
break;
case 2:
colName = "color";
break;
}
acc[colName] = value;
return acc;
},{})
"
# Incoming message
{
"data": ["Chevrolet","Camaro","yellow"]
}
# Outgoing message:
{
"crosser": {
"success": true
},
"data": [
"Chevrolet",
"Camaro",
"yellow"
],
"car": {
"brand": "Chevrolet",
"model": "Camaro",
"color": "yellow"
}
}
Using custom functions
Since it is JavaScript code you can declare and call your own functions as well. Below we mix the usage of the map function with a custom implementation to alter the layout of the flow message.
We get a string array in, but we want to output an array of objects in the format [{name: 'some-name', value: 'some-value'}]
# Settings:
Script = "
function stringArrayToKeyValueArray(str, ix) {
return {["col"+ix]: str};
}
msg.data = msg.data.map(stringArrayToKeyValueArray);
"
# Incoming message
{
"data": ["one","two","three"]
}
# Outgoing message:
{
"data": [
{ "col0": "one"},
{ "col1": "two"},
{ "col2": "three"},
]
}
Search Documentation
Process & Analyze
Custom Code & ML