- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-08-2020 08:30 AM
TL;DR
I needed a counter for flow designer, so I created one.
If you insist on reading the long version...
My job has not usually taken me down the road of using the flow designer much since its inception. However, in recent months, I've spent quite a bit of time with it. Having been on the platform for 12 years now, I've relied and appreciated mainly on a high/pro-code approach rather than a GUI. That said, I'm currently working on a project where we do not have administrative rights and are required to only develop in an application scope to build a solution. While this is probably not an issue for some of us, I found it quite difficult to adapt. I'm not going to go into all of my challenges here, but I did come across something that seems quite important and necessary that Flow Designer does not have: a counter/turnstile feature. I scoured the community and several other sites looking for a solution and found several that pretty much all said the same thing: create a table that serves as a placeholder for your counter value or even a scratchpad. These are fine solutions, albeit very involved and with some hefty overhead. Being the "lazy" developer that I am (always looking for an easier way to do things), I came up with a bit of a different solution. After talking this issue over with one of my colleagues
I'll set this up so you can see what I did and replicate it:
First, you need to use a subflow so you can have an input. I created an integer input for my subflow called max_iterations.
I then created an action that I called Create Counter Array
For the Input on the action, I created a Max Number (max_number) as an integer.
I then created a script step that contains the following:
Note the input and output variables. I'll put the code here so that it's easier to copy/paste:
(function execute(inputs, outputs) {
var countArr = [];
//create array given max number
var maxNum = parseInt(inputs.max_number);
for (var i = 1; i <= maxNum; i++) {
countArr.push(i);
}
outputs.counter_array = countArr;
})(inputs, outputs);
Finally, I created an output for the action as follows:
And set the value as follows:
I then went back to the subflow I created and added an action step for the Create Counter Array at the root of my subflow as follows:
From there, I was able to loop through the array and do what I needed to do just like we would with a counter or turnstile.
Keep in mind you'll need an end in your loop if you've accomplished what you needed to during the loop and do not need further loops.
As mentioned, I don't spend a lot of time in Flow Designer. If any of you have a better solution. Please let us know. I'm just posting what worked for me because it literally took me two days to get to a solution I was comfortable with. It would be nice if we had an OOB solution, heck, we might and I just don't know it.
Thanks for listening and I hope I help at least one person.
- 5,108 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for sharing this helpful solution! 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is brilliant, and will totally hold me overuntil we get Flow variables in Quebec. Well done