Ashok Bala
Ashok Bala

Reputation: 168

condition in Transform Message - Mule

I want to transform message in mule application based on some condition.

%dw 1.0
%output application/json
---
{
    **// create the below if the size of payload is greater than 0**
    resource_type : "speciality",
    speciality_name : payload[0].speciality_name,
    speciality_description : payload[0].speciality_description,
    uuid : payload[0].uuid

   **//else create the below message**
   message : "No records were fetched from backend"
}

Could any one please kindly help me on this?.

Upvotes: 0

Views: 631

Answers (1)

AnupamBhusari
AnupamBhusari

Reputation: 2415

You can use when otherwise condition for this. Like

%dw 1.0
%output application/json
---
{
    // create the below if the size of payload is greater than 0**
    resource_type : "speciality",
    speciality_name : payload[0].speciality_name,
    speciality_description : payload[0].speciality_description,
    uuid : payload[0].uuid
} when payload != null and (sizeOf payload) > 0 otherwise
{
   //else create the below message**
   message : "No records were fetched from backend"
}

Hope this helps.

Upvotes: 4

Related Questions