2

Using Mule 3.3, I've got a Payload (which starts out as a JSON and I'm converting it to an Object using java.util.HashMap). I can access the variables just fine from a JDBC query using:

#[message.payload.AddJob.variable1]

How do I go about adding a new variable (say variable2), or modifying the value of an existing variable?

I've tried:

<message-properties-transformer doc:name="Message Properties">
    <add-message-property key="message.payload.AddJob.variable2" value="&quot;hello&quot;"/>
</message-properties-transformer>

Which had no effect.

I also tried a groovy Script (below) as suggested here: How to add additional data to a mule payload?, but it overwrites the entire payload with "hello", not just variable2.

payload['AddJob.variable2'] = 'hello'
Community
  • 1
  • 1
Benjamin Bryan
  • 351
  • 1
  • 8
  • 21

1 Answers1

9

What with:

<expression-transformer
            expression="#[message.payload.AddJob.variable2='hello';message.payload]" />

?

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • The Expression Transformer isn't doing what I want, it's overwriting the entire payload instead of just that one variable (or map?). This is the output from the echo component before the expression transformer: `* Message received in service: nwa_soap_add_job_flow. Content is: * * '{AddJob={JobNumber=12345, Variable2=B5}}'` After the expression transformer: `* Message received in service: nwa_soap_add_job_flow. Content is: 'hello' *` What I want the result to be is: `{AddJob={JobNumber=12345, Variable2=hello}}` – Benjamin Bryan Sep 27 '12 at 16:19
  • My bad, I forgot to return the map with the added element, I changed the expression accordingly. – David Dossot Sep 27 '12 at 19:24
  • That worked for both adding new vars and modifying existing. Thanks! – Benjamin Bryan Sep 27 '12 at 20:29
  • This saved me a lot of time, thanks ... I was not adding the last `message.payload` statement -_- – Ahmad Hajjar Mar 19 '18 at 05:54