Skip to main content

Node - Loop


Overview

The Loop node repeatedly runs a sequence of workflow actions. You can run the loop for a specified number of iterations or continue running it until an exit condition is met.

Two loop modes are available:

  • Loop While Conditions Are Met

    Repeats the loop until the configured exit condition is met. Custom parameters can be updated during each iteration and used to control when the loop ends.

  • Loop a Specified Number of Times

    Uses start, end, and step parameters to control the number of iterations. The loop ends when start becomes greater than end.

Notes:

  • Loop iterations run strictly sequentially.
  • Each iteration counts as one workflow execution.

Loop a Specified Number of Times

Example: Randomly select 10 questions from a question bank of 100 questions to generate an exam.

In each iteration, use a Get Single Data node to randomly retrieve one question, copy it to the exam, and mark the source question as selected. After 10 iterations, clear the selection marks from the question bank.

Add a Loop Node

Add a Loop node and select Loop a Specified Number of Times.

Configure the Loop

Configure Loop Parameters

This mode includes three predefined system parameters: start, end, and step. You can set their initial values, but the parameters cannot be deleted or renamed.

  • start: The current loop value. The loop starts with the configured initial value.

  • step: The amount added to start after each iteration. For example, if start = 1 and step = 2, start becomes 3 after the first iteration.

  • end: The value used to determine when the loop ends. Once start becomes greater than end, no further iterations are run.

You can also pass custom parameters into the loop.

In this example, each iteration needs to access the newly created exam record. Pass the exam record ID (exampaperid) as a custom parameter so that the record can be retrieved within the loop.

Add Custom Parameters

To add a custom parameter, add it in the first node of the loop.

Understand When the Loop Ends

With Loop a Specified Number of Times, the loop ends when start becomes greater than end.

For example:

  • start = 1, step = 1, end = 3: The loop runs 3 iterations. After the third iteration, start becomes 4, so the loop ends.
  • start = 1, step = 2, end = 3: The loop runs 2 iterations. After the second iteration, start becomes 5, so the loop ends.
  • start = 1, step = 1, end = 0: The loop runs 0 iterations.

Maximum Number of Iterations

A Loop node can run up to 10,000 iterations.

When the limit is reached, the loop ends automatically and the workflow continues with the nodes after the Loop node. This limit applies even if start has not yet become greater than end.

Pass the Triggering User

Enable Use the triggering user of this workflow for the loop to pass the triggering user of the current workflow to the loop.

If this option is disabled, the loop is triggered by Workflow.

Handle a Terminated Iteration

If an iteration is terminated, configure how the Loop node should proceed:

  • Skip and Continue to the Next Iteration: Stop the current iteration and proceed with the next one.
  • End the Loop and Continue the Workflow: Stop the current iteration, end the loop, and continue with the nodes after the Loop node.
  • Terminate the Workflow: Stop the entire workflow containing the Loop node.

Configure the Actions in the Loop

Open the Loop node to configure the actions that run during each iteration.

In this example, the actions run up to 10 times. Each successful iteration randomly retrieves one question. When the iteration finishes, start increases by 1 and the next iteration begins.

After the 10th iteration, start becomes 11, which is greater than end, so the loop ends.

If the question bank contains only 6 questions, the Get Single Data node returns no record during the 7th iteration. The workflow can then use the Abort Process node to stop the iteration, after which the Loop node handles the termination according to the configured behavior.

Complete the Workflow

After the loop ends, clear the selection marks from the questions that were selected.

Loop While Conditions Are Met

This mode includes one predefined system parameter: index. Its value automatically increases by 1 after each iteration.

You can also define custom parameters and update them during the loop. These parameters can be used in the exit condition to determine when the loop should end.

Example: Retrieve all pages of data from a paginated API.

Some APIs do not return the total number of pages. Instead, the response indicates whether more data is available and provides a cursor for retrieving the next page.

For example, an API may return:

  • has_more to indicate whether another page is available.
  • next_cursor to identify where to continue retrieving data.

In this case, use Loop While Conditions Are Met to continue requesting data until no more pages are available.

Add a text parameter named hasMore, set its initial value to true, and configure the loop to exit when hasMore equals false.

After saving the configuration, open the automatically created loop and configure the actions for each iteration.

First, add a node that calls the integrated API and pass the required parameters to the API.

Next, add a Branch node to handle the API response:

  • If data is returned, process the returned data.
  • If no data is returned, update hasMore to false to end the loop.
  • If another page is available, update cursor with the returned next_cursor value and proceed to the next iteration.
  • If no additional page is available, update hasMore to false to end the loop.

How this mode works: Custom parameters are updated during the loop until the configured exit condition is met. If the exit condition is never met, the loop continues until it reaches the maximum number of iterations.

Update and Use Loop Parameters

Update Loop Parameters

Use an Update Parameters node to update custom parameters during a loop.

The predefined system parameters (index, start, end, and step) cannot be modified using an Update Parameters node.

Use Loop Parameters After the Loop

After the loop ends, subsequent nodes can reference the final values of its parameters.

Reuse an Existing Loop

If the required loop has already been configured, you can reuse it instead of creating a new one.

In the Loop node, select Use an Existing Loop Process, then select the app and the loop to reuse.

Was this document helpful?