For Each Loop Loops Too Many Times

  • 11 December 2017
  • 3 replies
  • 1 view

Badge +7

I have a list of all the sites in our site collection. For each site, the members and owners are populated. I add each member and owner to their own collection variables, then I loop through the collection variable to get their display name and add them to a list via build string. This list will go in the body of the notification so the recipient can know who all the owners and members of their site are without having to navigate there.

Once all the owners and members have been added to the collection, we evaluate and remove based on certain criteria (not a valid employee in AD, a VIP, etc.). In my latest test, I have removed 3 owners and 2 members. The problem is that the loop will continue 3 more times and add the last person's name to the list each time. It appears to be adding extra semicolons at the end. This does not coincide with any owners or members I have removed from the list (removed 2 members, added 3 semicolons). I have a commit pending changes after each build string in the loop. What is going on? I've used For Each loops to do this very logic in other workflows and this hasn't happened.


3 replies

Userlevel 6
Badge +12

‌ - 

Are you reusing the same collection variables for each site? If so, are you ensuring that they are empty? 

I have done something similar and had to ultimately clear the collection and reset my index back to [0].

Hope this helps!

Badge +7

Thank you for that insight. I had to clear not one, but two variables in order to get my list. Thank you!! laugh.png

Userlevel 6
Badge +12

Happy to help!

Reply