switch script node

Routes incoming Message to one OR multiple output chains. Node executes configured JavaScript function.
JavaScript function receive 3 input parameters:
msg
- is a Message payload.metadata
- is a Message metadata.msgType
- is a Message type.
The script should return an array of next Relation names where Message should be routed. If returned array is empty - message will not be routed to any Node and discarded.

Message payload can be accessed via msg
variable. For example msg.temperature < 10;
Message metadata can be accessed via metadata
variable. For example metadata.customerName === 'John';
Message type can be accessed via msgType
variable. For example msgType === 'POST_TELEMETRY_REQUEST'
Full script example:
if (msgType === 'POST_TELEMETRY_REQUEST') {
if (msg.temperature < 18) {
return ['Low Temperature Telemetry'];
} else {
return ['Normal Temperature Telemetry'];
}
} else if (msgType === 'POST_ATTRIBUTES_REQUEST') {
if (msg.currentState === 'IDLE') {
return ['Idle State', 'Update State Attribute'];
} else if (msg.currentState === 'RUNNING') {
return ['Running State', 'Update State Attribute'];
} else {
return ['Unknown State'];
}
}
return [];
Last updated
Was this helpful?