Why fruitless foreach returns N lines ?

Certified Senior Developer

Hi,

I'm trying to test a fruitless foreach, and I'm surprised to see that the result is not just null or empty.
- can you tell me why this code returns 20 null lines please (please see the attached file) ? I was expecting an empty list-

- In this case, how to assert that the result is fruitless ?

a!localVariables(
  /* Get a list of 20 Vehicles */
  local!vehicles: a!flatten(rule!CJT2_GetVehiclesWithFilters(
    id: null
  ).data),
  
  /* The id = 550 does not exist in the Vehicles so we'll not find it */
  local!oneVehicle: a!forEach(
    items: local!vehicles,
    expression: if(tointeger(fv!item.id)=550, 
      fv!item, 
      {}
    )
  ),
  
  local!oneVehicle
)


The object of this post, is not to replace foreach by another function (like index or reject) but to understand how works the foreach.

Regards

  Discussion posts and replies are publicly visible

Parents Reply Children