Daniel
Daniel

Reputation: 89

Route the process based on conditions

Am trying to route the process based on input payload.

input:

{
    "data": {
        "schema": "rWdXQ7M38dwTJ8Ro29S8PQ",
        "payload": {            
            "ChangeEventHeader": {
                "changeType": "CREATE",
                "changedFields": [


                ],
                "Name": "Case",
                "recordIds": [
                    "a77V00000000vI4IAA"
                ]
            },
            
            "Last_Month_Work_Billed_RS__c": 0.0
        },
        "event": {
            "replayId": 10198245
        }
    },
    "channel": "/data/Job__ChangeEvent"
}

I am using choice connector in mule 4

the data weave expression am using is below

payload.data.payload.ChangeEventHeader.changeType == "CREATE" & Name != " "

It gives me error. how can i achieve this through expressions?

Upvotes: 0

Views: 80

Answers (3)

Alex
Alex

Reputation: 4473

Please, provide error what you have. Try

payload.data.payload.ChangeEventHeader.changeType ~= "CREATE" and payload.data.payload.ChangeEventHeader.Name != " " and payload.data.payload.ChangeEventHeader.Name?

Upvotes: 2

Ray A
Ray A

Reputation: 447

You can also explore this syntax:

payload..changeType[0] == "CREATE" and !isEmpty(payload..Name[0])

isEmpty(<expression>): https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-isempty

Upvotes: 1

olamiral
olamiral

Reputation: 1296

Dataweave dos not understand the ampersand symbol as a logical operator (in this case, 'and'). Also, you should add the full path to the 'Name' property.

Use the following dataweave expression:

payload.data.payload.ChangeEventHeader.changeType == "CREATE" and payload.data.payload.ChangeEventHeader.Name != " "

Dataweave logical operators are described here: https://docs.mulesoft.com/mule-runtime/4.3/dw-operators#logical_operators

Upvotes: 1

Related Questions