Reputation: 77
I am new to dataweave language. Could you please help to solve this syntax error "Invalid input "otherwise (", expected is, *, <=, <, >=, as, or,
, ~=, -, functionCall, ==, fullAttributes, +, !=, :, and, / or >" at first occurence of word "otherwise' below.
%dw 1.0
%output application/json
---
{
ref:[{
captureDetails : {
captureSource : "aa",
captureDate : ""
},
effectiveDate : "",
expiryDate : "",
preferenceLevel : "customer",
sourcePreferenceCode: {
(( preferenceCode: "A1" ) when trim payload.key == "REF1"
otherwise (
( preferenceCode: "A2" ) when trim payload.key == "REF2"
otherwise (
( preferenceCode: "A3" ) when trim payload.key == "REF3"
otherwise (
( preferenceCode: "A4" ) when trim payload.key == "REF4"
otherwise (
( preferenceCode: "A5" ) when trim payload.key == "REF5"
otherwise (
( preferenceCode: "A6" ) when trim payload.key == "REF6"
otherwise (
( preferenceCode: "A7" ) when trim payload.key == "REF7"
otherwise (
( preferenceCode: "A8" ) when trim payload.key == "REF8"
otherwise ( preferenceCode: "" )
)
)
)
)
)
)
)
),
preferenceValue: trim payload.value
},
}],
lastUpdateDetails:{
lastUpdateId:"adam",
lastUpdateTimestamp:"2019-07-19",
lastUpdateFunction:"U",
lastUpdateChannel : "P"
}
}
Upvotes: 0
Views: 367
Reputation: 1538
I would use the match
operator which should be clearer for this case:
%dw 1.0
%output application/json
---
{
ref:[{
captureDetails : {
captureSource : "aa",
captureDate : ""
},
effectiveDate : "",
expiryDate : "",
preferenceLevel : "customer",
sourcePreferenceCode: {
preferenceCode: (trim payload.key) match {
"REF1" -> "A1",
"REF2" -> "A2",
"REF3" -> "A3",
"REF4" -> "A4",
"REF5" -> "A5",
"REF6" -> "A6",
"REF7" -> "A7",
"REF8" -> "A8",
default -> ""
},
preferenceValue: trim payload.value
}
}],
lastUpdateDetails:{
lastUpdateId:"adam",
lastUpdateTimestamp:"2019-07-19",
lastUpdateFunction:"U",
lastUpdateChannel : "P"
}
}
Upvotes: 2
Reputation: 1023
Not sure why you have so many parentheses. This should work:
%dw 1.0
%output application/json
---
{
ref:[{
captureDetails : {
captureSource : "aa",
captureDate : ""
},
effectiveDate : "",
expiryDate : "",
preferenceLevel : "customer",
sourcePreferenceCode: {
preferenceCode: "A1" when trim payload.key == "REF1"
otherwise preferenceCode: "A2" when trim payload.key == "REF2"
otherwise preferenceCode: "A3" when trim payload.key == "REF3"
otherwise preferenceCode: "A4" when trim payload.key == "REF4"
otherwise preferenceCode: "A5" when trim payload.key == "REF5"
otherwise preferenceCode: "A6" when trim payload.key == "REF6"
otherwise preferenceCode: "A7" when trim payload.key == "REF7"
otherwise preferenceCode: "A8" when trim payload.key == "REF8"
otherwise preferenceCode: "",
preferenceValue: trim payload.value
}
}],
lastUpdateDetails:{
lastUpdateId:"adam",
lastUpdateTimestamp:"2019-07-19",
lastUpdateFunction:"U",
lastUpdateChannel : "P"
}
}
Upvotes: 2