Loop for each

Use loop actions A tool for building the processes, logic, and direction within workflows. to repeatedly run a set of child actions. The Loop for each action iterates through each item in a collection A variable containing multiple items, such as email addresses. Collection variables are useful for storing and operating on query results. For example, you can set up collection variables for names, email addresses, and index values to store results from querying a list. You can then loop through items in a particular collection variable (names, emails, or index values). variable, running its child actions during each iteration. When all items have been processed, the workflow proceeds to the next action after the Loop for each container.

With the SharePoint Online actions, you can use the Loop for each action to process collection items within Objects.

If you are looking for a particular item, you can optionally stop the Loop for each action when that item is found.

Before you begin: 

  • Understand Variables

  • Understand container actions. You can add actions to create branches such as Branch by stage or to contain other actions such as Action Set that can be collapsed down into a single action high-level view.

Jump to:

Configure the Loop for each action

Note: Actions using the Loop for each variable should be used only within that Loop for each action construct. Moving such associated actions outside the loop construct will cause configuration errors.

You can add the Loop for each action to a workflow in the following scenarios:

Stop processing the collection early

You can skip the rest of the items in the collection once you've found what you need. For example, if your goal is to find the item "425-555-1234" within a collection of phone numbers, then you can stop processing the collection variable once the item is found.

  1. Click the Loop for each action.

  2. For Stop processing, select a Boolean variable.

    Note: By default, a single Loop for each action can process a single target collection containing a maximum of 1,000 items.

  3. Add logic to your workflow that sets this variable to Yes when the condition for stopping is achieved.

    For example, within the loop construct of the Loop for each action, you might add the Branch by condition action, with the Set a variable value action on the Yes branch, where the condition is satisfied when you find the item you want. In the Set a variable action, you can set the Boolean variable to Yes.

Examples