1

I will let the code do the explanation.

Dataweave gives errors:

Unable to resolve reference of when

Unable to resolve reference of otherwise

Input Message: An array of objects. Though I have given only 1 object here.

[{
    "Field1" : 12345,
    "field2" : 10
}]
%dw 2.0
output application/json
---
payload map {
"test" : $.Field1 when $.field2 >= 1 otherwise ""
}
Nadeem
  • 77
  • 1
  • 12

1 Answers1

4

Nadeem there is no <expression> when <condition> otherwise <expression> in DW 2.0. Use if (condition) <then_expression> else <else_expression> instead.

So your code will be as follows:

%dw 2.0
output application/json
var data = [{
    "Field1" : 12345,
    "field2" : 10
}]
---
data map {
    test : if  ($.field2 >= 1) $.Field1 else ""
}
George
  • 2,758
  • 12
  • 16
  • That worked. Thank you. I should really look into the differences between DW 1.0 and 2.0 especially with regards to conditional statements. – Nadeem May 05 '20 at 13:16