The length function is not working correctly without using flatten

Certified Associate Developer
Here, the integrationResponse.result.body is an array of dictionaries. However, the length function returns 1 if not using flatten. Not sure why this is happening. Please share comments/reasons if any.

  Discussion posts and replies are publicly visible

Parents
  • Length is one of the primitive functions and as such, its use is constrained by some picky (and sometimes unintuitive) back-end stuff.  I'm not sure exactly what's going on here of course but as Stefan mentioned, it might help to see some of the raw JSON data being returned.  My first guess is that it's being confused by the exact data type of the ".body" result, perhaps interpreting it as an array of 1 item consisting of an array of the 5000 items we see - or something like that.  a!flatten() will of course smoothe this out, explaining why the result you see with that is coming out better.  That doesn't indicate a "problem" with length(), per se, as much as the fact that there are weird corner cases where its (correct) behavior is unintuitive.

Reply
  • Length is one of the primitive functions and as such, its use is constrained by some picky (and sometimes unintuitive) back-end stuff.  I'm not sure exactly what's going on here of course but as Stefan mentioned, it might help to see some of the raw JSON data being returned.  My first guess is that it's being confused by the exact data type of the ".body" result, perhaps interpreting it as an array of 1 item consisting of an array of the 5000 items we see - or something like that.  a!flatten() will of course smoothe this out, explaining why the result you see with that is coming out better.  That doesn't indicate a "problem" with length(), per se, as much as the fact that there are weird corner cases where its (correct) behavior is unintuitive.

Children
No Data