All functions

Appian enumerate()

Make a list of counting numbers when you have no list to loop over. Starts at 0, which is one less than every other position in Appian.

Official Appian documentation

The shape

enumerate() takes a count and hands back that many whole numbers, starting at 0.

enumerate(5)   →   {0, 1, 2, 3, 4}

Five numbers, and the last one is 4. It is a list of positions, not a list of things.

Why it exists

Every other way of looping in Appian starts from a list you already have. enumerate() is for when you do not have one — you know only how many times something should happen.

Ten blank rows in a grid, a retry counter, the first N of a series: there is no list to loop over, so you make one.

The trap: it counts from 0, and nothing else does

This is the whole reason the function is worth a lesson. Appian counts from 1 nearly everywhere else:

  • index(list, 1, "") gives you the first item
  • fv!index is 1 on the first pass of a loop
  • enumerate(3) gives you 0, 1, 2

So the numbers from enumerate() are almost always one less than the number you actually want. Adding one fixes it for the whole list at once, with no loop:

enumerate(5) + 1   →   {1, 2, 3, 4, 5}

That works because arithmetic already applies itself to every item of a list. It is the same element-wise behaviour that makes most a!forEach() calls unnecessary.

Edges worth knowing

  • enumerate(0) is an empty list. Useful rather than annoying: loop over it and the body never runs.
  • A negative count is an error, not an empty list. Guard the count if it comes from data.
  • A decimal count is cut down to a whole number, so enumerate(2.7) gives two numbers.

Pairing it with a real list

Because the numbers are positions, they pair with index() to walk a list by position:

a!forEach(items: enumerate(3), expression: index(names, fv!item + 1, ""))

Note the + 1 again. When you already have the list, looping over the list itself and using fv!item is shorter and harder to get wrong — reach for this pairing only when the position is genuinely what you are working with.

Try it

Run each one and read what comes back before moving on.

1Ask for five numbers and count what comes back.

enumerate(5)

2Shift the whole list up by one, without a loop.

enumerate(5) + 1

Compare the two counters inside a loop. One comes from enumerate, one from the loop itself.

a!forEach(items: enumerate(3), expression: fv!item & " / " & fv!index)

1Ask for none.

enumerate(0)

2Now ask for a negative count.

enumerate(-1)

Use the positions to read a list you already have.

a!forEach(items: enumerate(3), expression: index({"a", "b", "c"}, fv!item + 1, ""))

Independent evaluator — approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

Exercises

0 of 5 cleared
  1. 1enumerate(): count from 1 to n
  2. 2enumerate(): build numbered row labels
  3. 3enumerate(): project a loyalty balance visit by visit
  4. 4enumerate(): count down to a launch
  5. 5enumerate(): label the pages of search results
Start the first exercise