mule studio - How to print record values without repeating certain fields in dataweave in CSV format based on specific conditions -
please consider following input sample in csv
company,firstname,lastname,email rate,manule,reaya,reaya@egetmetus.org rate,sholy,bonvgy,bonvage@mollis.org
the output should follows :
company,firstname,lastname,email rate,manule,reaya,reaya@egetmetus.org ,sholy,bonvgy,bonvage@mollis.org
the condition : if company name repeats different records in input, should null in output csv.
please let me know if can handled in dataweave component in mule
below updated code
<?xml version="1.0" encoding="utf-8"?> <mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd"> <configuration doc:name="configuration"> <expression-language> <global-functions> def getcompanyname(company){ if (flowvars.companylist contains company) { return ""; } else { flowvars.companylist.add(company); return company; } } </global-functions> </expression-language> </configuration> <file:connector name="file" autodelete="true" streaming="true" validateconnections="true" doc:name="file"/> <file:connector name="file1" autodelete="true" outputappend="true" streaming="true" validateconnections="true" doc:name="file"/> <flow name="csvtocsvrecordemptyflow"> <file:inbound-endpoint path="src\test\resources\input" connector-ref="file" responsetimeout="10000" doc:name="file"/> <set-variable variablename="companylist" value="[[]]" doc:name="variable"/> <dw:transform-message doc:name="transform message"> <dw:set-payload><![cdata[%dw 1.0 %output application/csv header=true --- payload map { companyname: getcompanyname($.company), name:$.firstname }]]></dw:set-payload> </dw:transform-message> <file:outbound-endpoint path="src\test\resources\output" outputpattern="test.csv" connector-ref="file1" responsetimeout="10000" doc:name="file"/> </flow> </mule>
afaik, problem store used company names within memory using dataweave. don't think can done. if combine, mel global functions , dataweave, should able achieve this.
add global mel function in mule config below -
<configuration doc:name="configuration"> <expression-language> <global-functions> def getcompanyname(name){ if (flowvars.companylist contains name) { return ""; } else { flowvars.companylist.add(name); return name; } } </global-functions> </expression-language> </configuration>
in flow, initialize empty array before dataweave.
<set-variable value="#[[]]" variablename="companylist" doc:name="variable" />
then, in dataweave, use mel function -
... companyname: getcompanyname($.name) ...
you can write custom logic in mel function can evaluate name , return value dataweave.
Comments
Post a Comment