Else If in Dataweave 2.0

I am trying to write else if statement in my Data weave but getting the error expression missing ""

PBSI__Tax_Code__c                   : if((payload.order.customer."billing-address"."country-code" =="NL") "${sf_taxcode}" else if(payload.order.customer."billing-address"."country-code" =="DE") "${sf_deTaxcode}"),

2 Answers

The expression is missing the else of the last if sentence. It is mandatory to have an else.

As a simplified example:

{
    PBSI__Tax_Code__c: 
        if(country_code =="NL") "something" else if(country_code =="DE") "something" else "something else"
}

Also note that it in DataWeave configuration properties are accessed with the p() function.

%dw 2.0
output application/json
---
{ 
    PBSI__Tax_Code__c : 
    if(payload.order.customer."billing-address"."country-code" =="NL") p('sf_taxcode') 
    else if(payload.order.customer."billing-address"."country-code" =="DE") p('sf_deTaxcode')
    else "as default"

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest