To use Automate Studio, understand the concepts of nodes, variables, debugging, and passing data between nodes.
Flows
A flow is a series of nodes that work together to perform a specific task, like transcribe a video.
Variables
Usually, as data moves through a flow, the data is scoped to one node at a time. However, you can use variables to change the scope of the data so it's available across the entire flow or even multiple flows.
Message (msg) object
An all-purpose JavaScript object created automatically by Automate Studio that handles data as it passes between nodes. msg has global scope and visibility, so you can access it from all the nodes and sub-flows of a flow.
The msg object contains a payload property by default. The value of the payload property changes as various nodes of the flow process your data. You can attach a Debug node to any node and check the Debug panel after running the flow to review the payload field's value.
[Tip] To see how the msg object changed from node to node, you can wire Debug nodes to some or all of a flow's nodes, then set each Debug node to output complete msg object and run the flow to see messages from all Debug nodes in the debug panel in the sidebar.
You can add properties to the msg object. For example, to keep totaling a variable during the flow, create the total field in a Change node by editing the node's properties so that it sets the msg.total field to some initial value. This would create the total property and initialize it. You can then update msg.total in subsequent Function nodes in the flow.
At the end of a flow, you can retrieve data from the msg.payload field.
Context, flow, and global objects
In addition to the msg object, in the Function node there are three objects that can store node data: the context, flow, and global objects. Each object has its own scope:
- context - has scope within the node
- flow - has scope within the flow or sub-flow
- global - can be accessed by all flows in the application
Examples of getting and setting data
The following examples show how to use flow context to get data and set data. You can use the context and global context similarly.
In a Function node, this defines a variable called myVar that's available across the entire flow:
flow.set("myVar","hello world")
To retrieve myVar anywhere in the flow, you call flow.get() and specify the variable name (myVar):
var myVar = flow.get("myVar")
You can reassign this variable at any time. The new value doesn't have to be the same data type and can be any valid JavaScript datatype.
var myVar = flow.get("myVar")
if( myVar === "hello world" ) {
myVar = 0
} else {
myVar = ["a","b","c"]
}
flow.set("myVar", myVar)