Search code examples
jsonforeachmuleanypoint-studio

MuleESB. How to stop for each loop?


Good day, collagues. Give me the cue, pls. In one my case for JSON parsing i am using FOR EACH component with Choice inside him. Like this: enter image description here

After http request i have in the paylaod some JSON result, which represents of some collection. Foreach treats every item from collection and compute it's properties with condition in Choice component.

I want to stop the loop when condition in Choice was found. I don't want to compare all items of result collection.

I tried to change the variable 'counter' inside the Fore each loop. But it is not working.

May be anybody has found the way?


Solution

  • You may not be able to do this using a for-each. But you could always have an expression/groovy script to do this loop and breaking based on your condition. Please refer this: Is there a break statement in Mule <foreach>