0

I am on Mule 4. I need to create a "filter string" (to be used in an API call) from an array. A sample input array is given below:

[
  "123AAA","123BBB","123CCC","123DDD","123EEE"
]

I need to get an output string like this using dataweave 2.0 ID = '123AAA#DT' OR ID = '123BBB#DT' OR ID = '123CCC#DT' OR ID = '123DDD#DT' OR ID = '123EEE#DT'

I tried using joinBy function but since this is in an array, it was giving an error. Please advise.

1 Answer 1

3

It seems a good candidate for reduce().

%dw 2.0
output application/json
---
payload reduce ((item, accumulator="") -> "ID = '" ++ item ++ "#DT'" ++ (if (accumulator != "")  " OR " ++ accumulator else "" ))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.