Flow: How To Use “Counter”
Continue from the Loop article, here we would like to introduce how you can repeat the same actions for a specific number of times by using “Counter” in flow.
Counter is not an out-of-the-box functionality, rather it is more of a foundemental tool of all programming languages. The concept is very easy – you create a variable, and use it to track how many repetitions have been run. Let’s dive into the steps of how to achieve that.
Step 1 – Create a number variable
First you need to have a number variable, call it Counter, and set the default value to 0.
Step 2 – Create Decision element to set the breaking point
To tell the system when to break the repetitions, we need to add a Decision element. Then you set two outcomes and use the goal number to separate the two. For example, if we want to run it 10 times, the first outcome would be when the counter is < 10, and the second outcome is counter >= 10.
Step 3 – Add actions inside the loop
After having the Decision, add actions that will run in each repetition, and connect with the first outcome that we created. (When counter has not reahced our goal). Remeber to move the add to collection action to another assignment! (Here is just to demonstrate they are a set of actions)
Step 4 – IMPORTANT! Edit the counter using Assignment
As the counter is an ad-hoc variable that we created, we have to let the system know once a repetition is done running. To achieve that, use an Assignment element to modify the counter, namely add 1 to the counter. By doing so, the counter can now track how many repetitions have been run.
*** NOTE: You can move the add to collection action from the previous assignment to this assignment.
Step 5 – IMPORTANT! Close the loop
Same as Loop element, you will also need to close the loop manually when using Counter.
Step 6 – Add actions after the loop is done
If you want to continue your flow after all the repetitions are done, add the elements and connect with the second outcome. (When the counter is over the goal)
Then we finish with how Counter should be set up and utilized!
Great explanation – Thanks for making an article! Was able to get this to work in our org.
Nice to hear! Glad that it was helpful Dave😊