Variables and Compose
1. Variables and Compose
Flows can be dynamic, but on their own they can't remember anything between steps. Variables and Compose fix that, and are the building blocks for everything that follows.2. Why store values?
You'll store a value in a flow for three reasons. The first is reuse, where you fetch a value once at the top, often a trigger input like Project Name from the Parameters tab, and then reference it in every action that follows. The second is update, for a running counter or an accumulating string that needs to change as the flow runs. The third is compare, so a Condition or Switch downstream can branch on the value you've held.3. Initialize variable
Variables follow a two-step pattern, where you initialize first, then update. Initialize Variable is always the first variable action in a flow, and it declares three things, the name, the type, and the starting value. Six types are available, including String, Integer, Float, Boolean, Array, and Object. Each variable also needs its own Initialize action. A critical rule is to always initialize before you use. If Set, Append, Increment, or Decrement runs before Initialize, the flow fails immediately.4. Updating variables
Once a variable is initialized, there are three sets of update actions. Set Variable replaces the entire value, Append adds onto the end of a string or array, and Increment or Decrement add or subtract from a number. Be aware that using Set inside a loop only keeps the last item added. We'll see why next.5. See it in action
Here's one of the most common mistakes with variables, along with how to spot and fix it. Dan at Vantara is building a weekly report for Crestline Logistics, with three active projects to compile into one report. The flow loops through the project list using Set inside the loop. When you run it, only project gamma shows up in the final report, and alpha and beta have vanished. Opening the loop reveals what happened. On the first iteration, the flow sets the report to alpha, on the second it overrides that with beta, and on the third with gamma. Set replaces the value every single time, so only the last item survives. The fix is to swap Set for Append. Once that change is in place, the Crestline report shows all three projects, because Append builds onto the existing value instead of overwriting it. The rule worth remembering for every loop is simple, which is that inside a loop you should always reach for Append rather than Set.6. Compose
Compose stores a value too, but it behaves differently, because you write it once, set it, and never change it. There's no type declaration needed either, since Compose infers the type from whatever you give it. It can also go anywhere in a flow, including inside loops or branches, while Initialize Variable has to be at the top level. The most practical use for Compose is as an expression debugger, where you drop one in, write the expression you want to test, run the flow, and read the output. Once you've confirmed it works, you can remove it.7. Variables vs Compose: when to use each
Here's a quick comparison. Compose allows for a write-once approach, while Variables are updated as needed. Compose does not require type declaration, while Variables require one. Compose can be used anywhere in the flow, while Variables must be initialized at the top level. In terms of performance, Compose is lightweight when used in loops, whereas Variables can cause locking in parallel. Finally, Compose is best suited for snapshots and debugging, while Variables are ideal for counters and accumulators. In summary, choose Variables for changing values, and Compose for values that are computed once and reused unchanged.8. Let's practice!
Now it's time to initialize your first variable and see how Compose and variables work together in a real flow.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.