0

I have an output from a webservice in Mule that returns a linkedHashMap and I need to get the individual values to be dynamically inserted into a template. The template is used to send email through the SMTP connector. I can get all values using MEL #[payload], but I can't get them one by one. I've tried #[payload.get(0)], #[payload[0]] but they all return null.

The Mule XML looks like this:

<flow name="MW_Flow">
    <file:inbound-endpoint path="C:\....\1" connector-    ref="File" responseTimeout="10000" doc:name="File" pollingFrequency="60000"/>
    <ws:consumer config-ref="File_Read_WS" operation="all3" doc:name="FileRead DBWriter WS"/>
    <dw:transform-message metadata:id="6ee92ba8-9f67-40d6-bfa3-3e237da20822" doc:name="Transform Message">

<foreach doc:name="For Each">
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <parse-template location="C:\.....\Templates\Mail.txt" metadata:id="b7d894eb-465b-47f7-a542-b49fc4fb53d9" doc:name="Parse Template"/>
        <logger message="2: #[message.exception] #[message.dataType] #[payload]" level="INFO" doc:name="Logger"/>
    </foreach>
</flow>

The template (plain text file) looks a bit like this:

Hello [name]. This is email from [name2]. The following event [event].....

All I get are null values except when using #[payload] which returns the whole row (4 values).

Any help greatly appreciated! /Johan

Slim
  • 5
  • 2

1 Answers1

0

If your payload is a Map then payload.get(0) or payload[0] will behave as if you are trying to get a value from map with 0 as key, which I guess doesn't exist in your map.

Try accessing it with name - #[payload.name] or #[payload.name2] or #[payload[name]]

Manik Magar
  • 1,403
  • 2
  • 10
  • 20
  • I tried those but they didn't work, but using the "." made me try another way which actually worked, #[payload.column_name] Quite obvious in retrospect... Anyways, thx for your quick response! – Slim Apr 22 '16 at 17:50
  • Glad it worked! Do you mean #[payload.column_name] worked? If yes, then that's what I had mentioned in answer #[payload.name], I assumed you have name key in map because you was using that in template :). – Manik Magar Apr 22 '16 at 17:53
  • Yes, #[payload.column_name] worked! I didn't realize that at first because the actual name of my column wasn't name, I just wrote it here to make it simpler to understand :| – Slim Apr 22 '16 at 18:07