Repeat
Audience:
Low-code EngineersSkill Prerequisites:
Actions,Tokens,Conditions
Runs a list of actions several times. The loop can run:
- a fixed number of times, like a
forloop, usingRepetitions - while a condition is true, like a
whileloop, usingWhile Condition - both: while the condition is true, but never more than
Repetitionstimes
The current repetition number is available in the [<BaseNameToken>:CurrentLoopNumber] token, starting at 1.
Typical Use Cases
- Process data in batches, for example call a stored procedure once for each of 10 batches
- Poll an external service until a job finishes, with a maximum number of attempts
- Retry a call that sometimes fails
- Build up a value over several steps, for example a running total
Don't use it to
- Run actions for each row of a list or query result. Use Execute Actions for each List Entry instead.
- Run actions once with error handling. Use Execute Actions instead.
Related Actions
| Action Name | Description |
|---|---|
| Execute Actions for each List Entry | Runs actions once for each entry in a list. |
| Execute Actions | Runs a list of actions once, with error handling. |
| Wait | Pauses between repetitions, for example when polling or respecting rate limits. |
| Stop Execution | Ends the loop and all remaining actions. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Base Name Token | A name for the loop, for example Batch. It's used to build the [Batch:CurrentLoopNumber] token. Nested loops need different names. | Yes | empty string | Yes |
| Repetitions | The maximum number of times to run the actions. Must be a whole number greater than zero, for example 10 or [BatchCount]. Leave empty to repeat for as long as While Condition is true. | Yes | empty string | No |
| While Condition | A condition checked before each repetition. The loop stops as soon as it's false. For example [Job:Status] != "Done". Leave empty to rely on Repetitions only. | Yes | empty string | No |
| Actions | The actions to run in each repetition. | No | empty | Yes |
| Context Behavior | What happens to tokens created or changed during each repetition. See Context behavior. | No | Update all tokens in the original context | No |
| Continue on error | When checked, a failed repetition is written to the site's event log and the loop moves on to the next repetition. When unchecked, a failed repetition ends the loop. | No | Unchecked | No |
| On Error | Actions to run when a repetition fails. See How errors are handled. | No | empty | No |
If both Repetitions and While Condition are empty, the action does nothing.
Context behavior
Each repetition runs on a copy of the tokens. Context Behavior decides what's copied back after each repetition. This matters because the next repetition, the While Condition and the actions after the loop all read from the original tokens.
| Option | What's copied back after each repetition | Use it when |
|---|---|---|
| Update all tokens in the original context (default) | Every token created or changed in the repetition. | The next repetition, the While Condition or the actions after the loop need values from the loop. |
| Don't save the iteration tokens | Nothing. Every repetition starts from the tokens as they were before the loop. | Each repetition is independent and you don't need its results afterwards. |
| Update the tokens in the initial context | Only tokens that already existed before the loop. New tokens are discarded. | You want to carry specific values, such as a running total, without leaking other tokens. Create those tokens with an initial value before the loop. |
The While Condition reads the original tokens. With Don't save the iteration tokens, a condition based on a token that's changed inside the loop never changes, so the loop could run forever. Always set Repetitions as a safety limit when you use While Condition.
How errors are handled
| Continue on error | On Error | What happens when a repetition fails |
|---|---|---|
| Unchecked | empty | The loop ends and the error is passed up. |
| Unchecked | has actions | The On Error actions run. If one of them ends execution, for example Display Message, execution ends there. Otherwise the error is passed up. |
| Checked | any | The On Error actions run, the error is written to the site's event log, and the loop continues with the next repetition. Messages, redirects and other results from On Error are ignored. |
Unlike Execute Actions, the On Error actions of Repeat don't receive the [Exception], [ExceptionMessage] and related tokens. To capture error details, put an Execute Actions with its own On Error inside the loop.
Considerations
- Actions that end execution end the loop and all remaining actions. If an action inside the loop shows a message, redirects or is Stop Execution, no further repetitions run and the actions after Repeat don't run either.
- Unique names. The action fails with A loop with the name ... already exists if
Base Name Tokenis already in use by an enclosing loop. Loops that run one after the other can reuse a name. - After the loop. The
[<BaseNameToken>:CurrentLoopNumber]token is removed when the loop ends. - Numbers in conditions. Token values are compared as numbers when the other side is a number, so
[Batch:CurrentLoopNumber] <= 5works. - Long loops hold up the request. In forms and grids, keep the number of repetitions small, or run the loop in Execute Actions Asynchronously.
Examples
To understand how to use the below examples, please see Running Examples.
1. Process ten batches
This action calls a stored procedure ten times, passing the batch number 1 to 10.
{
"Title": "Repeat",
"ActionType": "LoopActions",
"Description": "Process batches 1 to 10",
"Condition": null,
"Parameters": {
"BaseNameToken": "Batch",
"Repetitions": "10",
"EndCondition": "",
"ActionList": [
{
"Title": "Run SQL Query",
"ActionType": "RunSql",
"Parameters": {
"ConnectionString": "",
"QueryTimeout": "",
"SqlQuery": "EXEC dbo.ProcessBatch [Batch:CurrentLoopNumber]",
"BindTokens": "",
"OutputTokenName": "",
"ExtractColumns": "",
"OnError": [],
"ShowErrors": false
}
}
],
"ContextBehavior": {
"Expression": "",
"Value": "NoPreserve",
"IsExpression": false,
"Parameters": {}
},
"ContinueOnError": false,
"OnError": []
}
}
2. Poll a job until it finishes
This action checks a job's status every two seconds until it's Done, for at most 15 attempts. The query saves the status in [Job:Status], and Update all tokens in the original context copies it back so the While Condition sees the new value. Before the first check, [Job:Status] is empty, so the condition is true.
{
"Title": "Repeat",
"ActionType": "LoopActions",
"Description": "Wait for the export job to finish",
"Condition": null,
"Parameters": {
"BaseNameToken": "Poll",
"Repetitions": "15",
"EndCondition": "[Job:Status] != \"Done\"",
"ActionList": [
{
"Title": "Run SQL Query",
"ActionType": "RunSql",
"Parameters": {
"ConnectionString": "",
"QueryTimeout": "",
"SqlQuery": "SELECT Status FROM ExportJobs WHERE JobId = [ExportJobId]",
"BindTokens": "",
"OutputTokenName": "Job",
"ExtractColumns": "",
"OnError": [],
"ShowErrors": false
}
},
{
"Title": "Wait",
"ActionType": "Wait",
"Parameters": {
"TimeMs": "2000"
}
}
],
"ContextBehavior": {
"Expression": "",
"Value": "UpdateAllTokens",
"IsExpression": false,
"Parameters": {}
},
"ContinueOnError": false,
"OnError": []
}
}
In this example [ExportJobId] comes from an earlier action, not from user input. Use Bind Tokens in Run SQL Query for values that users can change.
Revised 09/25/2026