Search code examples
mulemule-studiodataweavemulesoftmule-esb

Unable to concatenate a string with another variable


This is my code.

%dw 2.0
output application/java
var plantDesc = payload.somevalue
var str1 = "\"plantDescFull\" = " ++ "\"" ++ plantDesc ++ "\""
---
{
   testValue : str1
}

I need the output to be

{
   testValue : ""plantDescFull" = "someValue""
}

I have tried ways to set str1 but doesn't seem to work. Either I am not able to escape the the quotes or unable to put the value of plantDesc variable into str1

All help is appreciated


Solution

  • I think it works if you define it with single quotes:

    var str1 = '"plantDescFull" = "' ++ plantDesc ++ '"'