How to increment a numeric counter to control flow execution

Hi everyone,

I’m running into an issue with a scenario where I’m trying to control the execution flow using a variable (i). The goal is to stop uploading files to S3 after the first result meeting a specific condition has been processed. However, the variable i is not incrementing as expected, and every result is being pushed to S3.

Here’s the relevant flow:

  1. Set Variable (Initialization): I initialize the variable i to 0 at the start of the scenario, using the “execution” scope.
  2. Iterator and Router: An Iterator loops through an array of video results, and a Router checks if the duration of each video is greater than or equal to 10 seconds.
  3. Filter Condition: Inside the Router, I add a filter that checks if i = 0 to ensure only the first matching video is uploaded to S3.
  4. S3 Upload: If the condition passes, the video is uploaded to S3.
  5. Increment i: After the upload, another Set Variable module is supposed to increment i by 1 using this formula:

{{parseNumber(44.i) + 1}}

(Module 44 is where the variable i is set initially.)

Despite the increment step executing (verified via logs), the value of i is reset to 0 for each step in the iteration, and the condition i = 0 continues to pass for all iterations. The final “Set Variable” module appears to correctly increment i as execution logs indicate the output value of i is always after that step.

Context:

  • The variable i uses the “execution” scope to persist across iterations.
  • I suspect there might be an issue with how the variable value is being updated or retrieved in subsequent steps.
  • The scenario is configured to run in sequential mode, so execution order should not be an issue.

Questions:

  1. Why does the variable i not persist between steps in the iterate module when it is initialized outside of that scope?
  2. Is this a bug?
  3. Is there a better way to ensure only the first video meeting the duration condition is uploaded to S3?

Any guidance or alternative architecture suggestions would be greatly appreciated!

Thanks in advance for your help! :blush:

Hi @Matthew_Burke and welcome to the Make Community!

I’m not sure about my answer, but I’m interested in hearing what others have to say about this. My impression is that “i” is a static variable (or a constant) and you can’t change its value, you can only use it. But I could be wrong. I’ve never had to use it quite in the way you are.

L

Thanks for your feedback! This was a great suggestion that I hadn’t thought of, since at one point I was trying to use the Increment tool which uses the variable i.

Unfortunately I’ve just tried to replace i with currIndex and I’m seeing the same result.

I’ve also tried moving the Set Variable module to be the second module in the entire flow so it should only run once per entire execution, but I continue to see the same result where the variable is successfully initialized to 0, then incremented to 1 using the statement {{parseNumber(47.currIndex) + 1}}, only to be reset to 0 during each step in the final iteration.

I was able to solve this! I guess Variables just aren’t designed to be set and used as dynamically as I had assumed. I was able to achieve the desired flow execution using a Data Store which behaved just as expected.

It would be good if variables could be utilized like this since I only need a single key in this case, so the data store object is a bit heavy for this use-case.

2 Likes

Ah, that’s a great workaround. I hadn’t thought of that. Great job!

L