While Loop inside repeat turns into infinite loop, bug or just me being silly?

I have a scenario where I need to add a while loop inside a repeat.

The repeat goes through a database table of products, and then repeats through each record pulling additional API data for each, because the API has a 100 record limit I need to use a while loop to get the entire result set.

It would be very confusing to try show the exact script because its pretty large, but here is a small test case i created which runs infinitely.

Maybe its just not possible to do this as the global value is inside the repeat and so it can not reset it.

You never actually change the testValA value, so it always stays 1, which means the while loop will run infinitely.
You need to set the testValA value inside the while so it can end.

Im confused, I thought the blue highlighted step was resetting testValA to value 0 by referencing its Global Name, could you guide me as to how I should be resetting it please, now I am second guessing myself here, lol

Paul these are 2 different variables. They have different names:

Screenshot 2022-05-21 at 13.19.57

their names must be identical.

1 Like

Ahh I see, I did not realise that, I thought the variable names could be different as long as the Global Name was identical, thanks for clarifying, just tested and it is working now.

Looks like I am going to have to go change that in a dozen different projects i did incorrectly before.

I have different names all the time and it all works fine. I do it on purpose so I can distinguish clearly from local vs global. You just have to make sure you evaluate the proper name, which often means typing in the value instead of picking.

1 Like

I do the same Ken, this is the first time I have had this issue, would you mind testing my same case I screenshotted and seeing if there is some way you can figure out how to target it correctly if you are inside a repeated while loop like that, i tried various ways and could not get it right, I will admit though Teo’s solution worked right away, just changes how the flow works a bit for my script from what I am used to seeing.

You have been bitten by the bug that adds a carriage return in the set value! You can see it in your first screentshot. Nasty little bugger.

Here is what works.

Here’s the contents of the api test:

{
  "name": "repeat",
  "module": "core",
  "action": "repeat",
  "options": {
    "repeat": 3,
    "outputFields": [],
    "exec": {
      "steps": [
        {
          "name": "local_repeat_val",
          "module": "core",
          "action": "setvalue",
          "options": {
            "key": "global_repeat_val",
            "value": 1
          },
          "meta": [],
          "outputType": "number"
        },
        {
          "name": "",
          "module": "core",
          "action": "while",
          "options": {
            "while": "{{global_repeat_val==1}}",
            "exec": {
              "steps": [
                {
                  "name": "repeat_index",
                  "module": "core",
                  "action": "setvalue",
                  "options": {
                    "value": "{{'Repeat index: '+$index}}"
                  },
                  "meta": [],
                  "output": true,
                  "outputType": "text"
                },
                {
                  "name": "reset_global_repeat_val",
                  "module": "core",
                  "action": "setvalue",
                  "options": {
                    "key": "global_repeat_val",
                    "value": 0
                  },
                  "meta": [],
                  "output": true,
                  "outputType": "number"
                }
              ]
            }
          }
        }
      ]
    }
  },
  "output": true,
  "meta": [
    {
      "name": "$index",
      "type": "number"
    },
    {
      "name": "$number",
      "type": "number"
    },
    {
      "name": "$name",
      "type": "text"
    },
    {
      "name": "$value",
      "type": "object"
    }
  ],
  "outputType": "array"
}
1 Like

Brilliant, thanks Ken, I thought I had lost the plot for a moment there, lol. Now it all makes sense, my while loop condition could not equate because it was 0\n and not just 0

Thanks so much for testing that for me, really appreciate it.

1 Like

Hey folks, can someone post a link to the bug report about Set Value inserting a CR? I’d love to know the situations when this happens and to track when it is fixed!