How to loop first 100 rows for array using foreach?

Certified Associate Developer

I have 120 rows in array but i want to loop only first 100 rows using foreach function.

Please advise.

  Discussion posts and replies are publicly visible

Parents
  • Certified Lead Developer

    I usually use the two functions that can grab a piece of the array depending on length (with a bit of effort), rDrop() and lDrop().  These both drop a part of the array from the "left end" or "right end" depending on the value passed in.  It would be more straightforward if Appian had an equivalent function that lets you GET the left-or-right-most X items from an array, which would essentially be the inverse (or contrapositive?) of these two functions, and i'm unclear why they don't exist.  However you can accomplish it with just a bit of effort.

    a!localVariables(
      local!array: enumerate(120),
      local!originalLength: length(local!array),
      local!lengthWanted: 100,
      
      local!modifiedArray: rdrop(local!array, local!originalLength - local!lengthWanted),
      
      a!forEach(
        local!modifiedArray,
        fv!item
      )
    )

  • Certified Lead Developer
    in reply to Mike Schmitt

    , please help me. What is this foreach() doing?

  • Certified Lead Developer
    in reply to Stefan Helzle

    - in this case it's in place for demonstration.  OP's question was specifically about how they'd loop through "the first X rows of a Y-length array using a!forEach()", so my example here prepares a truncated array and then feeds it into a!forEach(), which would then contain arbitrary extra functionality, not seen here.

    Remember, having code that's readable, intelligible and maintainable is 100x more important than having code that's as-short-as-humanly-possible!

  • Certified Lead Developer
    in reply to Mike Schmitt

    OK. That makes sense. Thanks :-)

Reply Children
No Data