Hi,
In American flow, to transform DB map result to POJO, I have first saved the DB output to a variable. And using that variable as the input in TransformMessage element.
The code after in transformer looks as below after adding a condition over airlineName.
%dw 1.0
%output application/java
---
[{
airlineName : 'Delta' when flowVars.varDBResult.airlineName =='none' otherwise flowVars.varDBResult.airlineName as :string,
availableSeats: flowVars.varDBResult.seatsAvailable as :number,
departureDate: flowVars.varDBResult.takeOffDate as :string,
destination: flowVars.destination as :string,
flightCode: flowVars.varDBResult.code1 ++ flowVars.varDBResult.code2,
origination: flowVars.varDBResult.fromAirport,
planeType: flowVars.varDBResult.planeType,
price: flowVars.varDBResult.price as :number
} as :object {
class : "com.mulesoft.training.Flight"
}]
When I run this code, I am seeing below error.
Exception while executing:
airlineName : 'Delta' when flowVars.varDBResult.airlineName =='none' otherwise flowVars.varDBResult.airlineName as :string,
^
Cannot coerce a :array to a :string (com.mulesoft.weave.mule.exception.WeaveExecutionException). Message payload is of type: String
Even the ternary operator did not work.
Could you let me know where I went wrong.
Also is there any guide for 'TransformMessage' element which gives the MEL syntax details.
Regards,
Dev.
Here's the data weave code, sorry it does not show as required
%output application/java
%namespace ns0 http://soap.training.mulesoft.com/
%type flight = :object {class: "com.mulesoft.training.Flight"}
---
payload..*return map {
airlineName: $.airlineName,
departureDate: $.departureDate,
destination: $.destination,
availableSeats: $.emptySeats as :number,
flightCode: $.code,
origination: $.origin,
planeType: $.planeType replace /(Boing)/ with "Boeing",
price: $.price as :number {format: "# # # .# # "}
} as :flight