I’ve written a simple function using a foreach() statement that creates a list of values seperated by a carriage return. I’d like to include a counter so it can generate linenumbering as well, but I can’t find a way to do that. Does anyone know? Is it even possible?
In this case I usually use the following approach.
Lets say I have list of things called Items
Sequence(1, Count(Items).Foreach(
CurrentValue.WithName( I, RunActions(
// use Items.Nth(I) for the current item
// use I for the line number
))
)
Sequence(1,N) creates a list of numbers from 1 to N
CurrentValue.Withname(I, ... names the index as I
so that Items.Nth(I) it the items with that index
I also use this approach if I must iterate through more than one list, item by item.
Max
I think you’re probably looking for the sequence() formula along with the withname() formula. You can do something like this:
Sequence(1,
ListName.Count()
).ForEach(
WithName(ListName.Nth(CurrentValue),
TargetItem, [Your expression using TargetItem goes here]
)
)
Beat me to it, and with a better explanation.