The list starts empty. Then I want to append an value to it for each iteration in a loop if certain condition is met. I don't see append option in Variable Operation.
4 Answers
You can use string split for this, assuming you know of a delimiter that won't ever be in your list of values. I've used a semi-colon, and $local_joinedList$ starts off empty.
If (certain condition is met)
Variable Operation: $local_joinedList$;$local_newValue$ To $local_joinedList$
End If
String Operation: Split "$local_joinedList$" with delimiter ";" and assign output to $my-list-variable$
This overwrites $my-list-variable$.
If you need to append to an existing list, you can do it the same way by using String Join first, append your values to the string, then split it again afterward.
String Operation: Join elements of "$my-list-variable$" by delimiter ";" and assign output to $local_joinedList$

- 64
- 4
-
1I had this add a blank at the start in 10.5. I got around this by adding a local counter variable for the number of `if` matches. If that counter was 0, don't use the starter delimiting char. – Walls Dec 26 '18 at 16:29
-
This is a real pain. What if your data has the delimiter character in it. I would advise against this. It's not the best answer. Mareks is a more robust solution. But XML is such a pain to work with. I also miss no associative arrays -aka dictonaries or hashmaps! – JGFMK May 13 '19 at 08:37
Lists are buggy in Automation Anywhere and have been buggy for several versions. I suggest not using them and instead use XML.
It it a much more versatile approach and allows you to do much more that with lists. You can search, filter, insert, delete etc.
For the example you mention, you would use the "Insert Node" command.

- 2,698
- 1
- 20
- 30
-
The problem with XML, is that special characters need swapping out. Such as https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents There isn't even a method built into AA for that. Does AA automatically do this for you when you insert data with, say a chevron ? '<' – JGFMK May 13 '19 at 12:06
Throwing in my 2 cents as well - my-list-variable appears to be the only mutable in size list you can work with. From my experience with 10.7, it only grows though.
So if you made a list with 60 values, and you wanted to use my-list-variable again for 55, you'll need to clear out those remaining 5 values and create an if condition when looping over the list to ensure the values are not whatever you set those 5 values to be.

- 613
- 5
- 18
-
I'm on 11.3 and it doesn't work in that. So did things take a step back? https://i.stack.imgur.com/uuX7G.png – JGFMK May 13 '19 at 12:16
I used lime's answer as a reference (thanks lime!) to populate a list variable from some data in an Excel spreadsheet.
Here's my automation for it:

- 1,237
- 10
- 18