0

I tried the following way,

[dw('sizeOf payload.data.accts')>0] but hthis would just check if arraylist is empty or not .So i need a help to how do I null check on "accts" arraylist using dw() function.

I want both null and empty check in dw() function of mule so that I can use it in my choice router to proceed my flow.

Community
  • 1
  • 1
Shilpa
  • 101
  • 14

3 Answers3

0

I would do something like this in the choice router:

In the 'When' column: #[payload.data.accts != empty]

In the Route Message to column: yourFlow

greglorious_85
  • 71
  • 2
  • 15
  • But will the above case work for both null and empty check of an array @greglorious_85 – Shilpa Aug 02 '18 at 06:20
  • I'm not sure what your use case would be for needing to know if something is null and empty, but you should be able to just add an 'and' or 'or' clause to also check if is is null. – greglorious_85 Aug 02 '18 at 12:22
0

Please refer How to Check null condition in Data weaver : Mule.

Should be applicable to Json as well - try out

Example:(payload.Records.*RecordsEntries.*RecordEntry default [])

star
  • 1,493
  • 1
  • 28
  • 61
0

You can combine default with sizeOf to achieve this:

#[dw('(sizeOf (payload.data.accts default [])) == 0']

We can break this down into two expressions. The first, payload.data.accts default [] will return an empty list if payload, payload.data or payload.data.accts is null. Otherwise it will just return whatever the value of payload.data.accts is.

The second, (sizeOf <expression>) == 0 will check if the list returned from the above expression is empty or not.

jerney
  • 2,187
  • 1
  • 19
  • 31