Satya
Satya

Reputation: 51

Mule dataweave issue with when condition

Need help with a when condition in Dataweave transformation. My data weave transformer is populating email address in an output java object. The input email address comes from flow variable. I want to hydrate the output object only if email is stored in flow variable.

Below is the code I have and if I try to add a when condition, it throws an error. Can anyone please help with this conditional logic?

maintainContactInformationData: {
        effectiveDate: flowVars.currentDate,
        workerContactInformationData: {
            emailAddressData: [{
                emailAddress: flowVars.email ,
                usageData: [{
                    typeData: [{
                        primary: true,
                        typeReference: {
                            ID: [{
                                type: "Communication_Usage_Type_ID",
                                value: "WORK"
                            } as :object {
                                class : "com.workday.hr.CommunicationUsageTypeObjectIDType"
                            }]
                        } as :object {
                            class : "com.workday.hr.CommunicationUsageTypeObjectType"
                        }
                    } as :object {
                        class : "com.workday.hr.CommunicationUsageTypeDataType"
                    }]
                } as :object {
                    class : "com.workday.hr.CommunicationMethodUsageInformationDataType"
                }]  
            } as :object {
                class : "com.workday.hr.EmailAddressInformationDataType"
            }] when flowVars.email != null,

Upvotes: 1

Views: 1931

Answers (1)

Manik Magar
Manik Magar

Reputation: 1401

If you want emailAddressData to be added to output only when email variable is set the. You should include it in parenthesis ...

(emailAddressData: logic to get) when flowVars.email? And flowVars.email != ""

Upvotes: 2

Related Questions