Alessandro Alberani
Alessandro Alberani

Reputation: 82

Mule ESB - Get payload value

I'm not able to get the ID from the query result. Mule version is 3.5. This is the flow:

<flow name="mule.activity">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10000"/>
<db:select config-ref="JSDB" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT ID FROM ACTIVITY where rownum = 1]]></db:parameterized-query>
</db:select>
</poll>
<logger message="Current payload is #[payload]" level="DEBUG" category="mule.activity" doc:name="Logger"/>
<logger message="Current payload size is #[payload.size()]" level="DEBUG" category="mule.activity" doc:name="Logger"/>
<logger message="Current id is #[payload.ID]" level="DEBUG" category="mule.activity" doc:name="Logger"/>
</flow>

And this is the log

[2015-03-18 13:13:36,875] DEBUG: Current payload is [{ID=1363230}]
[2015-03-18 13:13:36,881] DEBUG: Current payload size is 1
[2015-03-18 13:13:36,888] DEBUG: id is null

Any help will be greatly appreciated.

Upvotes: 0

Views: 3511

Answers (1)

Dds
Dds

Reputation: 712

The returning payload of a query with the DB connector is always a list, whether is 0,1, or n elements. Your MEL expression is assuming it's a map: #[payload.ID] You should do something like #[payload.get(0).ID]

Then again I would advice you no to use this form to accessing maps

[payload.get(0).ID]

But rather

[payload.get(0)['ID']]

In the first example if you make a mistake with the id of the map you're trying to access the error isn't always that descriptive.

HTH

Upvotes: 1

Related Questions