Gwyll
Gwyll

Reputation: 13

How to retrieve data from list<String> in Mule for-each scope?

I am having some problems with iterating over a list collection in Mule, using the for-each scope. The iteration works fine, goes over every line, but I can't figure out how to extract the data I need. The revelant code part is below, 'Address' is a list, and I need to get each String from the list, which would be added to the 'finalString' variable, with some extra information.

<foreach collection="#[payload['Address']]" doc:name="For Each" counterVariableName="i" rootMessageVariableName="Original">
<set-variable variableName="finalString" value="#[flowVars['finalString']]" doc:name="Variable"/>
</foreach>

Upvotes: 0

Views: 5739

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

Within the foreach scope, each line will be represented by payload.

So you could use something like:

<foreach collection="#[payload['Address']]" doc:name="For Each" counterVariableName="i" rootMessageVariableName="Original">
   <set-variable variableName="finalString" value="#[flowVars['finalString'] + payload]" doc:name="Variable"/>
</foreach>

But that will look like "nulladdress1address2" but you can change this to check for null or concat differently.

Upvotes: 2

Related Questions