Iterating through nested Structures without nesting loops?
Service Studio Version
11.14.11 (Build 59394)

Hi All,

I have a nested Structure:


I need to iterate through all the Sites within the Structure.

Is this possible and correct to do with a singe For Each loop with the Record List property set to "CTCRequest.OrderPositions.Current.AssessmentSubjects.Current.Sites"?

The alternative from my limited experience would be to basically nest For Each-loops, which doesnt look that good to be honest.


Thanks!

~ Markus

Hello Afonso,

Thank you for your Explanation.

So the correct way to do this would actually look something like this?

The Record List properties in order from left to right are:

  1. CTCRequest.OrderPositions
  2. CTCRequest.OrderPositions.Current.AssessmentSubjects
  3. CTCRequest.OrderPositions.Current.AssessmentSubjects.Current.Sites

That looks really weird. 

mvp_badge
MVP

Hello Markus,

I don't think this is possible with a single loop. The "Current" value related to each list will only be affected by a loop that specifically iterates through it. Following your example, only the first set of Sites in the structure would be iterated (since both Current values would equal 0).

Hello Afonso,

Thank you for your Explanation.

So the correct way to do this would actually look something like this?

The Record List properties in order from left to right are:

  1. CTCRequest.OrderPositions
  2. CTCRequest.OrderPositions.Current.AssessmentSubjects
  3. CTCRequest.OrderPositions.Current.AssessmentSubjects.Current.Sites

That looks really weird. 

mvp_badge
MVP

Yes, this looks correct. I don't like nested loops either, but unless you're seeing serious performance or readability issues, it's the sort of thing that's safe enough to slap a comment on for the next person to read it.

If you just want to map, assign, you can use this approach explained by @Dorine Boudry.

https://www.outsystems.com/forums/discussion/77320/listappendall-only-appends-one-level/#Post319149

Regards,

Márcio

I either dont understand this well enough, or it doesn't help me because I want to do more than mapping.

However, this looks interesting and I will take a more detailed look into this tomorrow.

Thank you!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.