0
votes

How do I set a variable (using set variable transformer) based on the value in the payload ? where payload is of json format.

if payload.segmentation = local, then value of variable should be "material_reg"

if payload.segmentation = network, then value of variable should be "material"

1
What mule runtime is this? - maddestroyer7
Run time 4.2.2. Studio 7.41 - Nadeem

1 Answers

3
votes

You could use pattern matching:

%dw 2.0
output application/json
---
payload.segmentation match {
 case "local" -> "material_reg"
 case "network" -> "material"
}

Or just if/else clauses:

%dw 2.0
output application/json
---
if (payload.segmentation == "local") 
    "material_reg"
else 
    if (payload.segmentation == "network") 
        "material" 
    else 
        ""

Note that I'm using application/json as output but I think application/java or even text/plain would work for you since you just want a String variable.