[error] Error in executeScript_Sandbox code: Unexpected string

Hey guys, this is my second day using UI Vision and I am still just getting my feet wet. I have zero background in coding so I appreciate all and any help!

I am trying to create a simple loop counter but keep getting this error: [error] Error in executeScript_Sandbox code: Unexpected string

Can you please have a look at my code and let me know where I went wrong. Have been using the executeScript_Sandbox function since yesterday but this is my first time encountering this issue.

P.S. I wasn’t having any luck with {!loop} and {!times}, so I tried creating my own custom variable to keep count : ${myCounter}

Code:

{
“Name”: “loop-count”,
“CreationDate”: “2020-5-23”,
“Commands”: [
{
“Command”: “store”,
“Target”: “1”,
“Value”: “myCounter”
},
{
“Command”: “do”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “echo”,
“Target”: “Our current count is : {myCounter}", "Value": "green" }, { "Command": "executeScript_Sandbox", "Target": "return Number {myCounter} +1”,
“Value”: “Count”
},
{
“Command”: “repeatIf”,
“Target”: “${myCounter} < 3”,
“Value”: “Count”
}
]
}

To create a simple loop i use this code (i love simple short and fast code)

{
“Name”: “Loop_Some_Times”,
“CreationDate”: “2020-5-23”,
“Commands”: [
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorignore”
},
{
“Command”: “bringBrowserToForeground”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “0”,
“Value”: “Loop_Counter”
},
{
“Command”: “label”,
“Target”: “Engine_Code”,
“Value”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number (${Loop_Counter}) + 1”,
“Value”: “Loop_Counter”
},
{
“Command”: “echo”,
“Target”: “Loop Counter Is ${Loop_Counter}”,
“Value”: “#shownotification
},
{
“Command”: “gotoIf_v2”,
“Target”: “${Loop_Counter} < 5”,
“Value”: “Engine_Code”
}
]
}

Hey I appreciate the prompt response. I keep getting the error below when I paste in the code:

Unexpected token ‘“’ at 2:1
“Name”: “Loop_Some_Times”,

Nevermind I fixed it – looks like your quote symbols appear different from mine.

I fixed that and added a few $ here and there and it works! Thanks again :slight_smile:

It’s a bug of the forum the format, I pasted correct code but the forum have an error in format of code, the code works i use it.

1 Like

I get a different error and the loop never finishes. It seems the Loop_Counter variable is treated as a string.

Side note: I have been trying to write a loop for a few hours. The loop counter generates errors or seems to be treated as a string, so setting counter to 1, then executing script counter+1 returns 11.

The log is

  • [info]

Executing: | echo | Loop Counter Is {Loop_Counter} | #shownotification |

  • [echo]

Loop Counter Is {Loop_Counter}

  • [info]

Executing: | gotoIf_v2 | ${Loop_Counter} < 5 | Engine_Code |

  • [info]

Executing: | label | Engine_Code | |

  • [info]

Executing: | executeScript_Sandbox | return Number ({Loop_Counter}) + 1 | Loop_Counter |

  • [error][ignored]

Line 5: Error in executeScript_Sandbox code: Loop_Counter is not defined

  • [info]

Executing: | echo | Loop Counter Is {Loop_Counter} | #shownotification |

  • [echo]

Loop Counter Is {Loop_Counter}

  • [info]

Executing: | gotoIf_v2 | ${Loop_Counter} < 5 | Engine_Code |

  • [info]

Executing: | label | Engine_Code | |

  • [info]

Executing: | executeScript_Sandbox | return Number ({Loop_Counter}) + 1 | Loop_Counter |

  • [error][ignored]

Line 5: Error in executeScript_Sandbox code: Loop_Counter is not defined

  • [info]

Executing: | echo | Loop Counter Is {Loop_Counter} | #shownotification |

  • [echo]

Loop Counter Is {Loop_Counter}

  • [info]

Macro was stopped manually (Runtime 24.31s)

The code I copy-pasted from this thread:
{
“Name”: “loop”,
“CreationDate”: “2020-12-11”,
“Commands”: [
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorignore”
},
{
“Command”: “bringBrowserToForeground”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “0”,
“Value”: “Loop_Counter”
},
{
“Command”: “label”,
“Target”: “Engine_Code”,
“Value”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number ({Loop_Counter}) + 1”,
“Value”: “Loop_Counter”
},
{
“Command”: “echo”,
“Target”: “Loop Counter Is {Loop_Counter}”,
“Value”: “#shownotification
},
{
“Command”: “gotoIf_v2”,
“Target”: “${Loop_Counter} < 5”,
“Value”: “Engine_Code”
}
]
}

Did you double check the quotes like the user posted above?

Yes. Ctrl+R in Leafpad on Linux. Also the code window colours the lines differently if they have the wrong quotes around them. And the whole code would not run, instead of just the +1 command that the log shows red.

The macro code working

You pasted probably wrong format of commas or quotes

This macro code is created by me and working like a charm :slight_smile:

Glad it works for you. Shouldn’t commas or quotes make all commands in the macro fail, not just the iterate loop by +1 command? The log shows other commands running, only the +1 failing.
The UI.Vision RPA 5.9.5 code window colours wrong code differently, so this would also show wrong commas or quotes if these were the problem.

You copy and paste code with errors

Here missed $ in variable.

This macro code is made by me, when I posted it I tried it and working like a charm

Your code have error, fIx these errors please

{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number ({Loop_Counter}) + 1”,
“Value”: “Loop_Counter”
},
{
“Command”: “echo”,
“Target”: “Loop Counter Is {Loop_Counter}”,
“Value”: “#shownotification”
},

With

${Loop_Counter}

Every variable need to start with $

Warning; forum convert quotes format, need to replace it in correct quotes.

Your loop now works, thank you! The $ was the problem.
I will try to get my code working now also.

1 Like

There are multiple mode to create a loop, I suggest to use a better code using times command