I’m not sure if that’s a bug or a feature …
I wanted to use Sequence + Foreach with a Control as a variable, used in each “foreach”. I simplified my case because it’s a very complex formula.
So I have a button with this formula :
Runactions(SetControlValue(variable, 0), Sequence(1, 5).ForEach(SetControlValue(variable, variable+CurrentValue)))
I expected to have after a click : 1+2+3+4+5 = 15 in the control “variable” but I had 5. As if every foreach was executed at the same time, so without considering the new value of “variable”.
I found a workaround :
Runactions(SetControlValue(variable, 0), Sequence(1, 5).ForEach(RunActions(SetControlValue(variable, variable+CurrentValue))))
I think of it as an undocumented feature.
RunActions() updates values between interactions but it slows down the operation.
Yes, this is known and by design (although yeah, not really documented)
I always thought the only purpose of RunActions() was to allow specifying multiple actions with a comma in a block (top-level or within a FormulaMap()), and it could be easily omitted if the action was just one action.
I.e. I thought these were identical:
Sequence(1, 5).FormulaMap(
Table.AddRow(...)
)
Sequence(1, 5).FormulaMap(RunActions(
Table.AddRow(...)
))
Turns out they’re not:
Without RunActions(), Coda executes the action(s) right away without recalculating the doc between action…
Thanks for your answers
Now, I know !
system
Closed
June 17, 2024, 1:58pm
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.