Regressive loop website pages

I’m trying to do the following:
I need a countdown loop that starts, for example, from page 100 and decreases until it reaches page 1.

I’ve been trying to adapt the code below, but it stays in a loop on page 100 and doesn’t decrease to 99, 98, etc.

Where is the error? Here’s the code below:

"{
  "Name": "REGRESSIVE LOOP WEBSITE PAGES",
  "CreationDate": "2024-3-23",
  "Commands": [
    {
      "Command": "times",
      "Target": "100",
      "Value": "contador",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "100",
      "Value": "contador",
      "Description": ""
    },
    {
      "Command": "label",
      "Target": "inicio",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://mysite.com/page/${contador}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "${contador}-1",
      "Value": "contador",
      "Description": ""
    },
    {
      "Command": "gotoIf_v2",
      "Target": "${contador} > 1",
      "Value": "inicio",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}
    {
      "Command": "store",
      "Target": "${contador}-1",
      "Value": "contador",
      "Description": ""
    },

That is the bug. The store command can NOT do any math! You need to use executeScript_Sandbox instead.

I posted your question into ChatGPT 4, and it was answered perfectly, including a working JSON source code snippet :100: My only change would be that I recommend executeScript_Sandbox over executeScript for everything that does not need to interact with a website (e. g. decrementing a variable).

ChatGPT answer below: It is 100% correct :white_check_mark:

In UI.Vision, you can achieve a countdown of a variable by using a combination of the executeScript or executeScript_Sandbox command along with a loop structure. UI.Vision RPA is a browser extension that automates web and desktop applications. It uses a mix of visual recognition and Selenium-style commands to control web pages.

Here’s a simple step-by-step guide to counting down a variable:

  1. Initialize the Variable: Start by setting the initial value of your countdown variable using the store command.
  2. Create a Loop: Use the while or label and gotoLabel commands to create a loop. The loop will iterate until your variable reaches zero.
  3. Decrement the Variable: Within the loop, use the executeScript or executeScript_Sandbox command to decrement the variable. This is done by subtracting one from the variable’s current value.
  4. Check the Condition: After decrementing, check if the variable has reached zero. If it hasn’t, the loop continues; otherwise, it exits.

Here’s an example macro that counts down from 10:

{
  "Name": "countdown",
  "CreationDate": "2024-3-23",
  "Commands": [
    {
      "Command": "store",
      "Target": "10",
      "Value": "counter",
      "Description": ""
    },
    {
      "Command": "label",
      "Target": "startLoop",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Counter: ${counter}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number(${counter}) - 1;",
      "Value": "counter",
      "Description": ""
    },
    {
      "Command": "gotoIf",
      "Target": "${counter} > 0",
      "Value": "startLoop",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Countdown Complete!",
      "Value": "green",
      "Description": ""
    }
  ]
}

Thank you for your willingness to help.
I also initially tried to get help with chatgpt, but it always failed.

I tried to apply this script to my structure, but something went wrong.
I don’t know exactly where the error would be.

{
  "Name": "REGRESSIVE LOOP WEBSITE PAGES",
  "CreationDate": "2024-3-25",
  "Commands": [
    {
      "Command": "store",
      "Target": "10",
      "Value": "counter",
      "Description": ""
    },
    {
      "Command": "label",
      "Target": "startLoop",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "https://mysite.com/page/${counter}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number(${counter}) - 1;",
      "Value": "counter",
      "Description": ""
    },
    {
      "Command": "gotoIf_v2",
      "Target": "${counter} > 0",
      "Value": "startLoop",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Countdown Complete!",
      "Value": "green",
      "Description": ""
    }
  ]
}

What error do you get? Your macro works for me.