Strange behavior in a!forEach, null - {}

Certified Associate Developer

Please observe the result of these forEach, (1. and 2.):

1.

a!forEach(
   items: {1,2,3,4,5},
   expression:
   if ( fv!item > 3,
     fv!item,
     {}
   )

)

results in 

meanwhile

2. 

a!forEach(
   items: {1,2,3,4,5},
  expression:
  if ( fv!item > 3,
    fv!item,
    null
   )

)

results in 

Question: Why forEach 1. does not outcome five members in the list?, I expected this result

  • List of Variant - 0 items
      • List of Variant - 0 items
          • List of Variant - 0 items
          • 4(Number (Integer))
          • 5(Number (Integer))

            Discussion posts and replies are publicly visible

          Parents
          • 0
            Certified Associate Developer

            Hi Rafael,
            This is the expected result and this is a subtle behavior in a!forEach that often catches people off guard.
            Here’s the difference:

            • {} is treated as an empty list, so a!forEach skips that item entirely.

            • null is treated as a value, so it's included in the output list.

            That’s why in example 1, only 4 and 5 appear, the others were dropped because {} returns nothing. Using null ensures the full list structure is preserved.

            Hope that helps!

          Reply
          • 0
            Certified Associate Developer

            Hi Rafael,
            This is the expected result and this is a subtle behavior in a!forEach that often catches people off guard.
            Here’s the difference:

            • {} is treated as an empty list, so a!forEach skips that item entirely.

            • null is treated as a value, so it's included in the output list.

            That’s why in example 1, only 4 and 5 appear, the others were dropped because {} returns nothing. Using null ensures the full list structure is preserved.

            Hope that helps!

          Children
          No Data