Hello,

I want to iterate over a record list (from aggregate) and check if a specific attribute in this record list is also in another record list (local variable:list). If not, I want to expand the other record list. What I have right now throws the error "Ambiguous paths to For Each". Does anyone see what's wrong with the current logic?



Thanks in advance.


Hi,

Yes that top if that is leaving is own cycle can not be done. Everything inside a cycle needs that their flow ends in their own cycle. This means the cycle needs to run through all the records. The only way of breaking a cycle in the middle is containing it inside an action but this is something more complex of doing and I don't recommend to new developers.

Regards,

Marcelo

Hey,


If you really need to break the cycle and you can't create a new action, you can replace the forEach by a "if" pattern where you control the the conditions and the increment of the variables. Take in consideration that this approach can cause infinite loops.


Although, what I usually do is to have a forEach and right after a condition that avoids any further processing.

Hi moonwatah,


Please try this work-around. Instead of using the inner loop, use list filter action with the same condition which you assigned in the inner loop if widget and rest flow is same as your's.

Please refer the screen shot below. 


Hope it helps. Please do reply if it work's for you, I am eager to get your feedback (i don't know your requirement and flow, just an assumption work).


Kind Regards,

Benjith Sam

Hi

@Davide I wouldn't recommend that approach to someone that is starting with Outsystems. Beside infinite loops you need to control which element of the list to access and sometime developers forget to  check if those positions exist  

@Benjith In is core the list filter is nothing more than a cycle. And I already had problems with it performance wise when I used it inside a cycle and the lists were too big.

Regards,

Marcelo

Benjith Sam wrote:

Hi moonwatah,


Please try this work-around. Instead of using the inner loop, use list filter action with the same condition which you assigned in the inner loop if widget and rest flow is same as your's.

Please refer the screen shot below. 


Hope it helps. Please do reply if it work's for you, I am eager to get your feedback (i don't know your requirement and flow, just an assumption work).


Kind Regards,

Benjith Sam

Hi Benjith,


I ended up using your solution, but I must agree with Marcelo. It effects the performance which is why I think I will use a server action for a long-term solution instead.


Best regards


moonwatah wrote:

Benjith Sam wrote:

Hi moonwatah,


Please try this work-around. Instead of using the inner loop, use list filter action with the same condition which you assigned in the inner loop if widget and rest flow is same as your's.

Please refer the screen shot below. 


Hope it helps. Please do reply if it work's for you, I am eager to get your feedback (i don't know your requirement and flow, just an assumption work).


Kind Regards,

Benjith Sam

Hi Benjith,


I ended up using your solution, but I must agree with Marcelo. It effects the performance which is why I think I will use a server action for a long-term solution instead.


Best regards


Wanted to share how it looks right now:

This is the server action:

Hi moonwatah,

Thanks for sharing. But, I want to know by introducing a server action only for this purpose, is this  a good approach? because as per my knowledge and understanding the ListFilter action is a built-in OutSystems action which is optimized (inside which the same code which you used in the server action might be implemented).  I am eager to know what is the exact reason for going for the current approach (need clarification). 


Kind Regards,

Benjith Sam