JavaScript Processor
3 min
the javascript processor lets you write javascript in the code editor to add, remove, or modify fields in the message from an input tag why use the javascript processor use this processor when you need to reshape a message beyond what a fixed processor supports, for example, renaming a field (such as changing value to furnace pressure ), keeping only the fields you need and dropping the rest, deriving a new field from an existing value (such as adding an error field when value crosses a threshold), or reformatting a unix timestamp into a human readable one how it works write your script in the code editor, which supports syntax highlighting and real time validation learn more about javascript syntax on w3schools https //www w3schools com/js/ from the editor, you can also access playground , to test, write, and validate your script in real time before deploying it validate , to check your code working with input messages every message from the input is stored in an array called values use a for i, message in values{} statement to loop over it message holds the full incoming message for you to manipulate, and i identifies which connection wire it came from for a single input, you can replace i with since there's only one connection to distinguish both i and message are just variable names; you can name them whatever you like with multiple inputs, for example three connection wires named a, b, and c, i tells you which wire each message came from as the loop runs use if else logic to manipulate each input differently, or apply the same manipulation to all of them you can output the result for a single input only, or for all of them related topics use the javascript processor function docid 9ynggwcj55vz2dg8wsxa4