6

Can someone please let me know how to concatenate multiple values in mule?

Something like,

#[payload.getPayload()].concat(#[getSubject()])
Learner
  • 2,303
  • 9
  • 46
  • 81

4 Answers4

12

I assume you are using Mule 3.3.x or above. If so you can use Mule Expression Language(MEL).

One example using MEL is:

#['Hello' + 'World']

Or MEL also allows you to use standard Java method invocation:

#[message.payload.concat(' Another String')]

Cheat sheet on MEL

MULE 4 Update

For Mule 4. Dataweave 2.0 is the main expression language:

Simple concat:

#['Hello' ++ ' World']
Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
  • Is it possible to do #['Hello'] + #['World'] or #[message.payload.concat(#['World']) – Learner Feb 25 '13 at 22:23
  • You don't need the nested expression: #[]. You can access multiple values from a single MEL expression. For example if you want to concatentate a messgae property with the payload you can use:#[message.payload.concat(message.inboundProperties['http.method'])] or similar for different parts of the payload etc. You can use the #[string:] evaluator to use nested expressions but that works differently and the best practice is to use MEL. – Ryan Carter Feb 26 '13 at 10:27
0

Other alternative is to use Mule Design plugin :

Drop an "Append String" operation as many times as you need.

This operation takes the message payload of the previous step and concats a specified string to it. Not sure about performance details, but it will be surely more easy to maintain.

Append to String - MuleSoft

julianm
  • 2,393
  • 1
  • 23
  • 24
0

you can declare a string buffer using expression component

<expression-component doc:name="Expression"><![CDATA[StringBuffer sb = new 
    StringBuffer();
    flowVars.stBuffer=sb;
    ]]></expression-component>

and then append use append on string buffer any where in the flow.

flowVars.stBuffer.append("string to append")

Once done use #[flowVars.stBuffer] to access the concatenated string

user3366906
  • 149
  • 2
  • 11
0

If you want to add two different values received through payload in the mule flow then we can use concat() method.

For example below we have received values through arraylist where i am adding two diffrent fields i.e. FirstName and the LastName -

concat(#[payload[0].'firstname']," " #[payload[0].'lastname']

Sanjeet Pandey
  • 546
  • 4
  • 23