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:
In the Designer page:
-
Click the Logic and flow action group in the action toolbox.
or
Find actions by browsing action groups, or by typing an action name or function in the Search field at the top of the action toolbox.
-
Drag the Loop for each action to where you want to process a collection variable.
-
Click the Loop for each action.
- Under Target collection, select the collection variable containing the items you want to process.
Note: A single Loop for each action can only process a single target collection containing a maximum of 1,000 items.
- Select the appropriate Data type of items in the collection.
- (Optional) If you want to stop the looping process without iterating through all the items, select Yes for Stop processing and add logic to set conditions in your workflow. By default, the Loop for each action construct will iterate through maximum of 1,000 items. For more information on stop processing option, see Stop processing the collection early.
For more information on the fields, see Loop for each fields.
- You cannot use Collection operations actions for Loop for each actions that are configured to loop through a collection of objects A variable that groups several related variables of any type into a hierarchical structure. Objects can contain other Objects..
- When the Loop for each action is used to loop through an auto-generated output variable from an action (e.g., SharePoint Online - Query a list) that contains any deleted custom columns, a configuration error will occur. We recommend removing or replacing the deleted columns from the output variable.
In the Designer page:
-
Click the Logic and flow action group in the action toolbox.
or
Find actions by browsing action groups, or by typing an action name or function in the Search field at the top of the action toolbox.
-
Drag the Loop for each action to where you want to process a collection variable.
-
Click the Loop for each action.
- Under Target collection, select the collection variable containing the items you want to process.
Note: A single Loop for each action can only process a single target collection containing a maximum of 1,000 items.
- (Optional) If you want to stop the looping process without iterating through all the items, select Yes for Stop processing and add logic to set conditions in your workflow. By default, the Loop for each action construct will iterate through maximum of 1,000 items. For more information on stop processing option, see Stop processing the collection early.
For more information on the fields, see Loop for each fields.
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.
-
Click the Loop for each action.
-
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.
-
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.
Field | Description | Variable types |
---|---|---|
Target collection | Collection variable containing items to process. |
Collection |
Stop processing | Skips remaining items in the collection variable when the selected Boolean variable is set to Yes. | Boolean |
Data type | (Only appears when native target collection is selected.) The data type of the collection items. | Boolean, DateTime, Decimal, Integer, Text, File |
Examples
In this scenario, you want to store data received from a web form to a SharePoint list. One of the form fields is a Choice - Multiple control that allows the user to select products of interest. You decide to store this data in a SharePoint Choice column.
To successfully pass data to this Choice column, the list of products selected must be concatenated with semicolons and hashtags. For example, if someone selects GX1000 and MX2000 in the products of interest field, then the data must be formatted as "GX1000;#MX2000" to successfully pass into the Choice column.
To format the user input with semicolon-hashtag concatenation (;#), we'll use the Loop for each action.
-
Set up a form with a Multiple choice field.
These steps provide you with a web form that includes a Multiple choice field (list of products).
In the Designer page:
- At the top of the designer canvas on the Designer page, click Start event to open the Start event configuration panel.
- For Connector, select Nintex.
-
For Event, select Form.
- Click Design form to open the forms designer.
- Drag the Choice - Multiple control onto the canvas.
- Click the control to show its configuration panel.
- For Options (comma-separated), edit the options text as required.
- Click Apply changes to save the changes.
The form changes are saved and the workflow designer is displayed.
-
Add a workflow variable.
These steps provide you with variables for use in configuring the Loop for each action and its child actions.
- Click Variables at the top of the workflow designer.
- Click Create variable.
The Create variable section is displayed.
-
For Name, type AllChoiceItems
- For Type, select Text.
- Click Create.
-
Add and configure the Loop for each action.
These steps show how to set up the loop construct containing child actions for iterating through the collection of products (values entered in the form for the Multiple choice field).
-
Drag the Loop for each action onto the designer canvas.
-
Click the Loop for each action to display its configuration panel.
-
Populate configuration fields with variables as follows.
Field
Variable
Target collection Choice multiple 1 Data type Text
For more information on the fields, see Loop for each fields.
-
-
Append each value from the form to a new string.
These steps show how to add and configure the child actions within the loop construct used for processing the collection of products.
- Drag the Set a variable value action onto the designer canvas, within the loop construct of the Loop for each action.
- Click the Set a variable value action to display its configuration panel.
- For Variable, select the AllChoiceItems variable.
- For Value:
- Click Insert, from Workflow tab, select the AllChoiceItems variable and click Insert.
- In the Value field, next to AllChoiceItems variable, click Insert.
- In the Loop for each variable container, select Current item variable and click Insert.
- Append with ;# to format the user input with semicolon-hashtag concatenation.
The Value field should contain [AllChoiceItems] [Current Item];#.
-
Create the SharePoint item.
These steps show how to create the list item that includes the properly concatenated list of products within the Choice column.
- Drag the SharePoint Online - Create an item action onto the designer canvas, outside and after the loop construct of the Loop for each action.
- Click the SharePoint Online - Create an item action to display its configuration panel.
-
Populate configuration fields with inputs as follows:
Field
Input
Connection Your connection for the SharePoint Online site. SharePoint site URL Your SharePoint Online site List name Name of your list that includes a Choice column - Click Add field to add the Choice column.
-
In the field for your added column, insert the variable AllChoiceItems.
You're now ready to publish the workflow, submit a form with multiple values, and see the selected values reflected in a new list item.
In this scenario, you want to retrieve the attachments from a SharePoint Online list item and store the retrieved files in a SharePoint Online document library.
To successfully retrieve the attachments from a SharePoint Online list, first, you need to fetch the attachment names from the required list item and store it in a collection variable. Using Loop for each action, you can loop through the collection variable to retrieve individual attachments to store.
In the Designer page:
-
Store attachment file names to a collection variable using the SharePoint Online - Get attachment names action.
-
Click the SharePoint Online action group in the action toolbox.
or
Find actions by browsing action groups, or by typing an action name or function in the Search field at the top of the action toolbox.
- Drag the SharePoint Online - Get attachment names action to the point in the workflow when you want to retrieve the attachment names from the list item in your SharePoint Online list.
- Click the SharePoint Online - Get attachment names action.
-
Access the list that contains the list item you want for the operation
-
Select a SharePoint Online Connection.
-
Type a SharePoint site URL.
Example:https://domain.sharepoint.com/sites/hr
- Click Retrieve lists. Existing lists in the site is retrieved and displayed in the List name drop-down.
-
Select the List name that you want.
-
- For Item ID, specify the ID of the list item that you want to retrieve attachments from. You can insert a variable or type the value.
- For Result, click Add variable > Create variable.
- For Name, type attachmentnames and click Create & insert.
-
-
Loop through the collection variable to process the attachment names.
- Click the Logic and flow action group in the action toolbox.
- Drag and drop the Loop for each action after the SharePoint Online - Get attachment names action.
- Click the Loop for each action.
The configuration panel is displayed.
- To select the Target Collection:
- Click Insert.
- In the variable panel, select SharePoint Online > attachmentnames > Attachment name(s) and click Insert.
-
Retrieve item attachment using the SharePoint Online - Get item attachment by name action.
-
Click the SharePoint Online action group in the action toolbox.
or
Find actions by browsing action groups, or by typing an action name or function in the Search field at the top of the action toolbox.
- Drag the SharePoint Online - Get item attachment by name action to the drop zone () in the loop construct.
- Click the SharePoint Online - Get item attachment by name action.
-
Access the list that contains the list item you want for the operation
-
Select a SharePoint Online Connection.
-
Type a SharePoint site URL.
Example:https://domain.sharepoint.com/sites/hr
- Click Retrieve lists.
-
Select the required List name.
-
- For Item ID, specify the ID of the list item that you want to retrieve attachments from. You can insert a variable or type the value.
- For Attachment name:
- Click Insert.
- In the Loop for each variable section, select Loop for each > Current item and click Insert.
-
For Result:
- Click Add variable > Create variable.
- For Name, type attachmentOutput and click Create & insert.
-
-
Store the retrieved attachments in a SharePoint Online document library.
-
Click the SharePoint Online action group in the action toolbox.
or
Find actions by browsing action groups, or by typing an action name or function in the Search field at the top of the action toolbox.
- Drag the SharePoint Online - Store a file action after the SharePoint Online - Get item attachment by name action within the loop construct.
- Click the SharePoint Online - Store a file action.
-
Access the document library to store the files
-
Select a SharePoint Online Connection.
- For File, click Insert.
- In the variable panel, select SharePoint Online > attachmentOutput and click Insert.
-
Type a SharePoint site URL that has the document library you want to store the file in and click Retrieve libraries.
-
Select the required Document library.
- Select Yes or No for Overwrite file to specify if you want to overwrite if a file with the same name exists in the destination document library.
All the retrieved attachment files are stored in the selected document library.
-
-