UI.Vision RPA v6.2.8
If I interrupt a foreach loop, the !foreach variable doesn’t reset if i re-enter the same foreach at a later point in the macro. Instead it picks up where it left off.
Built some sample code below and output below. It loops 5 times on a foreach loop. The foreach loops on an array [A,B,C,D]. It jumps out of the foreach when it finds a ‘C’. Then when it re-enters the foreach, it picks up where it left off at letter D. Then on the next loop into the foreach, it goes back to the start of the array. I would have thought it should restart the array every time it enters the foreach…
Output:
This is loop number 1
Entering the ForEach…
ArrayValue = A !foreach = 0
ArrayValue = B !foreach = 1
ArrayValue = C !foreach = 2
This is loop number 2
Entering the ForEach…
ArrayValue = D !foreach = 3
This is loop number 3
Entering the ForEach…
ArrayValue = A !foreach = 0
ArrayValue = B !foreach = 1
ArrayValue = C !foreach = 2
This is loop number 4
Entering the ForEach…
ArrayValue = D !foreach = 3
This is loop number 5
Entering the ForEach…
ArrayValue = A !foreach = 0
ArrayValue = B !foreach = 1
ArrayValue = C !foreach = 2
Code:
{
"Name": "foreach",
"CreationDate": "2021-12-15",
"Commands": [
{
"Command": "executeScript_Sandbox",
"Target": "return ['A','B','C','D']",
"Value": "myarray",
"Description": ""
},
{
"Command": "times",
"Target": "5",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "This is loop number ${!times}",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "Entering the ForEach...",
"Value": "",
"Description": ""
},
{
"Command": "forEach",
"Target": "myarray",
"Value": "arrayvalue",
"Description": ""
},
{
"Command": "echo",
"Target": "ArrayValue = ${arrayvalue} !foreach = ${!foreach}",
"Value": "",
"Description": ""
},
{
"Command": "gotoIf_v2",
"Target": "${arrayvalue} == \"C\"",
"Value": "exit",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "label",
"Target": "exit",
"Value": "",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
}
]
}