While

Loop through items one by one

While

AI-generated

Overview

This node, named "While," is designed to loop through input items in batches, processing a specified number of items per iteration. It is useful when you want to handle large datasets incrementally or control the flow of data by breaking it into smaller chunks. For example, if you have 100 items and set a batch size of 10, the node will output 10 items at a time over multiple executions until all items are processed.

A practical use case includes paginating API requests or processing large arrays step-by-step without overwhelming downstream nodes or external services.

Properties

Name Meaning
Batch Size The number of items to return with each iteration. Must be at least 1.
Options A collection of additional settings:
  Reset Whether to reset the node's internal state and reinitialize with the current input data.
  Array Field Name The name of the field containing an array to loop through instead of the default input items. If set, the node loops through this array extracted from the first input item's JSON data.

Output

The node has two outputs:

  • Loop (first output): Contains the current batch of items being processed. Each item includes its JSON data and any binary data it may have had originally. Items are paired with their original index.
  • Done (second output): Emits items only when the entire input has been processed (i.e., no more batches left). Until then, this output remains empty.

If there are no items to process, the node returns null.

Dependencies

  • No external services or APIs are required.
  • The node relies on n8n's context storage to maintain state between executions.
  • No special environment variables or credentials are needed.

Troubleshooting

  • Error: Field "<fieldName>" not found in input data
    This occurs if the "Array Field Name" option is set but the specified field does not exist in the first input item's JSON. Verify that the field name is correct and present in the input data.

  • Error: The provided value is not an array
    Happens when the value found under the specified "Array Field Name" is not an array. Ensure the field contains an array structure.

  • No output or unexpected behavior
    Check if the "Reset" option is used appropriately. If the node is not resetting when expected, enable the reset option to reinitialize the internal state.

Links and References

Discussion