Skip to main content
Solved

Is it possible to use nested lists in AA?


Uzumaki
Forum|alt.badge.img+8
  • Navigator | Tier 3
  • 25 replies

Is it possible to use nested lists in AA? My goal is to add a list of strings to another list of strings.
In my bot I am using using the List: Add Item action to add a string list B to string list A.
The ideal scenario would be to begin with list A: [1, 13, 42] and add to it list B: [4, 12, 5] so that I end up with a nested list A: [[1,13,42],[4,12,5]].
I’ve tried to implement this and this is the result that I get when I run nestedListA.LegacyAutomation:listtoString():


As you can see above, I can’t print out the values using the message box and instead it points me to an object location. 

Does anyone have any advice on how I can store a list of lists (with the ultimate goal of adding that list of lists to a dictionary)?

Best answer by Uzumaki

I found my issue, so I will share it here in case anyone has a similar issue.

Long story short, if you plan to dynamically populate a list of lists, I recommend not doing that. When you add a list to another list, the list that is added is referenced by its object location, not by its static values. Meaning that if that child list that is added changes, your parent list will change.

For example in my scenario we had:

Loop N times

    clear tempList

 

    #Populate tempList 

    Add randStr1 to tempList

    add randStr2 to tempList

    add randStr3 to tempList

 

    #add tempList to a parent list (a nested list)

    add tempList to parentNestedList

 


 

The problem with the above code is that the values of tempList are not added to parentNestedList. Instead, a memory location that points to tempList is added to parentList. So, when I clear tempList and populate it with new data, ALL of the data in parentNestedList still points to the current value of tempList. So, if i looped 3 times through the code, by the end of it parentNestedList would be populated with 3 references to tempList and tempList would only contain the most recently added data.

If I had two separate child lists, list1 and list2, that were both added to a parent list, list3, then list3 would contain references to two separate lists, the first would point to list1 and the second would point to list2. The method that I was using above only had one reference list, tempList, which was being modified and therefore my parentList was not displaying in the way in which I had intended.

Hope this helps

 

View original
Did this topic help answer your question?

4 replies

Aaron.Gleason
Automation Anywhere Team
Forum|alt.badge.img+10
  • Automation Anywhere Team
  • 569 replies
  • April 8, 2025

Once you have a list within a list, you must loop through the outer list, then loop through the inner loops to access the values.

Is this just an exercise or do you have a specific reason for doing this?


Uzumaki
Forum|alt.badge.img+8
  • Author
  • Navigator | Tier 3
  • 25 replies
  • April 8, 2025
Aaron.Gleason wrote:

Once you have a list within a list, you must loop through the outer list, then loop through the inner loops to access the values.

Is this just an exercise or do you have a specific reason for doing this?

I’m not married to this format, but I am expected to extract some data and pass it to another bot as a dictionary and some of that data would need to be returned as a list, so my team decided that this convention would make the most sense.

Essentially the dictionary that I'm returning would look like:
Address: 145 house street

City: Cityville

Past_Tenants: [John, Jimmy, sue], [Bob, Sarra, Jinny]


I tried the outer - inner loop using the message box to test the results and for some reason it prints as if list B was added twice and list A was not added it all. I’ve added debugging to verify that list A is added properly, but when list B is added, it almost looks like it replaces list A which is strange.


Uzumaki
Forum|alt.badge.img+8
  • Author
  • Navigator | Tier 3
  • 25 replies
  • Answer
  • April 9, 2025

I found my issue, so I will share it here in case anyone has a similar issue.

Long story short, if you plan to dynamically populate a list of lists, I recommend not doing that. When you add a list to another list, the list that is added is referenced by its object location, not by its static values. Meaning that if that child list that is added changes, your parent list will change.

For example in my scenario we had:

Loop N times

    clear tempList

 

    #Populate tempList 

    Add randStr1 to tempList

    add randStr2 to tempList

    add randStr3 to tempList

 

    #add tempList to a parent list (a nested list)

    add tempList to parentNestedList

 


 

The problem with the above code is that the values of tempList are not added to parentNestedList. Instead, a memory location that points to tempList is added to parentList. So, when I clear tempList and populate it with new data, ALL of the data in parentNestedList still points to the current value of tempList. So, if i looped 3 times through the code, by the end of it parentNestedList would be populated with 3 references to tempList and tempList would only contain the most recently added data.

If I had two separate child lists, list1 and list2, that were both added to a parent list, list3, then list3 would contain references to two separate lists, the first would point to list1 and the second would point to list2. The method that I was using above only had one reference list, tempList, which was being modified and therefore my parentList was not displaying in the way in which I had intended.

Hope this helps

 


Forum|alt.badge.img+8
  • Navigator | Tier 3
  • 61 replies
  • April 9, 2025

@Uzumaki You can use List: Assign to create a shallow copy of list, this copied list will not change if original list changes. You can use this copied list instead, to create your nested list.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings