Reputation: 67
i have a choice flow control component that uses an expression as follows:
<choice>
<when expression="${LoggingFlag} == YES">SOME CODE</when>
<otherwise>SOME OTHER CODE</otherwise>
</choice>
Here LoggingFlag used is a key-value pair defined in the app.properties file.
LoggingFlag=NO
when i run the code i see the following error:
Execution of the expression "NO == YES" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Exception stack is:
1. [Error: unresolvable property or identifier: NO]
[Near : {... NO == YES ....}]
Can someone tell me what is the reason behind this issue?
Upvotes: 0
Views: 552
Reputation: 147
You can even try by reading the property value and storing it in a variable and then comparing the variable value with the string in choice component as follows:
<set-variable variableName="SetLoggingFlag" value="${LoggingFlag}" doc:name="SetLoggingFlag"/>
<choice>
<when expression="#[flowVars.SetLoggingFlag=='YES']">SOME CODE</when>
<otherwise>SOME OTHER CODE</otherwise>
</choice>
Hope this helps you!
Upvotes: 0
Reputation: 63
This error occurs due to Mule not being able to resolve the type of value, set to LoggingFlag while comparing it in choice. For this you need to explicitly change the type to string, so that Mule can compare the two easily. For that you need to use:
<choice>
<when expression="'${LoggingFlag}' == 'YES'">SOME CODE</when>
<otherwise>SOME OTHER CODE</otherwise>
</choice>
Upvotes: 2
Reputation: 250
You need to enclose the variables in when expression within single quotes ' '
<choice doc:name="Choice">
<when expression="'${LoggingFlag}' == 'YES'"><set-payload value="payload 1" doc:name="Set Payload"/></when>
<otherwise><set-payload value="payload 2" doc:name="Set Payload"/></otherwise>
</choice>
Upvotes: 0