1

I am trying to have a choice condition where i will run a flow depending if array is empty.

Example :

Input : {"data":{"detailsSearch":[]}}

My code :

1. #[payload.data.detailsSearch*.size() > 0]
2. #[payload.data.detailsSearch*?]

I am getting an Runtime exception :

org.mule.api.MessagingException: Execution of the expression "payload.data.detailsSearch*.size() > 0" failed. (org.mule.api.expression.ExpressionRuntimeException).

I am looking for snippet to check for empty and null for this array

3 Answers3

2

@Sandeep, you can try

#[dw('sizeOf payload.data.detailsSearch')>0]
Ralph Rimorin
  • 329
  • 2
  • 10
  • Hi @Ralph Rimorin, This syntax is failing when I check payload after the database select because the database is returning '[ ]' if there are no records. – muralidhar gumma Jun 22 '18 at 10:50
1

In Mule 4 you can use Dataweave expressions in a choice router. If using Mule 4, you can use Dataweave 2.0 syntax and the sizeOf function:

<choice>
    <when expression="#[(sizeOf(payload.data.detailsSearch)) > 0]">
        ...     
    </when>
</choice>

Otherwise if you are using Mule 3, you can just use MEL and java syntax. Like so:

...

Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
-2

Sandeep,

This MEL should work. Before this, to extract data like this you should convert json to java.util.HashMap object.

#[payload.data.detailsSearch == empty]