Im trying to write CSV within For-each loop in Mule 3.
- Reading CSV file
- Passing parameter to the API to get response
- if no response, will write into another csv file. To maintain parameter value i set record variable before API calling and no matches, would write into CSV.
But CSV file not generating within For-each loop.
<foreach collection="#[payload.names]" doc:name="For Each">
<foreach collection="#[payload.names]" doc:name="For Each">
<batch:set-record-variable variableName="userName" value="#[payload.Name]" doc:name="Record Variable"/>
<http:request config-ref="HTTP_Request_Configuration" path="/users" method="GET" doc:name="Users">
<http:request-builder>
<http:query-param paramName="name" value="#[payload.Name]"/>
</http:request-builder>
</http:request>
<choice doc:name="Choice">
<when expression="#[payload.results.size()>0]">
<dw:transform-message doc:name="Transform Message" >
<dw:input-payload mimeType="application/java"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/csv
---
[payload]]]></dw:set-payload>
</dw:transform-message>
<set-payload value="#[recordVars.userName]" doc:name="Set Payload"/>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="users.csv" path="C://output"/>
</otherwise>
</choice>
</foreach>
</foreach>