0
votes

I am using data weave connector in my mule flow ..

Details:- From input side I am getting collection of array and I want to convert into CSV and write into the file.

But for particular column I am getting duplicates value and I want to remove them through data weaver.But when I am putting distinct by in front of that particular column ...code is not Woking and my getting below exception.

"Cannot coerce a :string to a :array"

Below is the mapping I am doing from output side.

dw 1.0
%output application/csv
---
payload map ((value, index) -> {
   A1: $.A1 distinctBy $ ,
   B1 $.B1,
   C1: $.C1,
   D1: $.D1,
   E1: $.E1,
 F1: $.F1

))

Guys please let me know how to use distinct by for "A1 Column" or any trick to remove duplicates value for particular column inside the data weave even i have tried group by but same syntax error is coming.. :(

Cheers, Stevin

2

2 Answers

1
votes

Please find the same solution at MuleSoft Forum

1
votes

Use distinctBy $.A1 outside the map

dw 1.0
%output application/csv
---
(payload map ((value, index) -> {
 A1: $.A1,
 B1 $.B1,
 C1: $.C1,
 D1: $.D1,
 E1: $.E1,
 F1: $.F1
 )) distinctBy $.A1