Set value to payload using expression transformer

3.1k views Asked by At

I am wanting to invoke a function on payload which is a Java pojo to set a value.

<set-variable variableName="name" value="xyz" doc:name="Variable"/>
<foreach doc:name="For Each">
<expression-transformer expression="#[payload.setEventId(flowVars['name'])]" doc:name="Expression"/>
<logger message="#[payload.getEventId()]" level="INFO" doc:name="Logger"/>
</foreach>

But this is giving me error. Root Exception stack trace: org.mule.api.transformer.TransformerException: Expression Evaluator "null" with expression "payload.setEventId(flowVars['name'])" returned null but a value was required.

1

There are 1 answers

2
David Dossot On BEST ANSWER

The expression-transformer replaces the current payload with the value returned by the expression. I'm guessing setEventId is void thus the expression returns null, hence the exception.

Use an expression-component instead:

<expression-component>payload.setEventId(flowVars['name'])</expression-component>