Product Features
...
Analytics
Statistical Functions

Tengo Script

3min

The Tengo Script processor is used for creating scripts to manipulate data in various ways.

Tengo Script Overview

  • This processor uses Tengo scripting, with its rules similar to GoLang.
  • Simple Use case: The output you receive from DeviceHub message or from Analytics, might not be helpful, and you want to change the name of a field within that message.
    • e.g Instead of "value" you want your data to show "furnace pressure".
    • e.g Instead of having all fields of the message, you only want to have "success", "deviceId" and "value" and skip everything else.
    • e.g You want to add a custom field to the message, based on the "value" field, such as: if value = 2, "error": "overheating".
    • e.g You only want to change the timestamp to human readable format instead of Unix timestamp, but keep otherwise keep the message as-it-is.
    • In general, if you want to add, remove or modify ANY field in the input, this scripting processor is very useful.
  • Single Input: Every message from the input, is stored as an array called "values".
    • Using "for i, message in values{}" statement, allows to access this input and manipulate it.
    • Here "i" represents what is the definition defined in the connection wire, more useful for multi-inputs, to identify and distinguish between each inputs, so for single input, "i" can be replaced with "_".
    • "message" contains the entire message in the input, and you can perform your manipulations to this "message" parameter.
    • Note: "i" and "message" can be any custom variable name.
  • Multiple Input: Suppose you have 3 different inputs attached to this scripting processor, with the connecting wires named A, B and C.
    • "for i, message in values{}" will now have 3 inputs.
    • "i" represents from which connection wire is the input coming from.
    • with if-else statements, every input can be manipulated in isolation, or a common manipulation can be applied to all inputs
    • You can choose to output "result" only for one input, or all of the inputs.
  • Miscellaneous information:

Tengo Script Parameters

Parameters

Details

Timeout

This parameter specifies the timeout in milliseconds for the script execution. You can set the timeout to control how long the script is allowed to run before it is considered as timed out.

Tengo Script parameters
Tengo Script parameters


Note: When creating an analytics flow with Tengo Script processor, refer the Use the Tengo Script Function guide for more details.