How To: Create a Loop Through a List of Items using SharePoint

In most instances, when you configure the Loop Step with a reference, it works as you expect, allowing you to use information about each item in each Next Item iteration of the loop. You only need to follow the instructions in this topic if your reference's list method does not contain an input property to retrieve a single record, and all record information in the reference is returned as a concatenated string in each loop iteration.

When you use a SmartObject method in the Loop step, the method must have an input property to load a particular record in the reference, typically an ID, autonumber or GUID, but it could also be a non-key field that acts as a filter on the method. This means that you’re passing a key or filter field as an input to the method, and that the field selected in the Create Reference step is the same as the input on the SmartObject method that you use in the Loop step. If you don’t match these or there is no input property on the method, all rows are returned and concatenated for each iteration of the loop.

The Loop step is designed to use the references to get each referenced item's values from the SmartObject when it starts each loop. When there are no more items in the reference, the loop completes.

A SmartBox SmartObject Get List method automatically includes the input property for passing in the ID, but other service object methods (such as SharePoint) do not. For more information, see the How To: Create a Loop Through a List of Items topic.

Service object methods, such as the Get List by View method for SharePoint, do not always contain an input field. You can still configure looping in your workflow using the service object methods by creating a Loop Index and then using this index as the identifier.

This How To shows you how to create the Loop Index and configure the loop in a workflow. This example is meant for illustration purposes only and is not a best practice.

Before you begin

This How To assumes that you are familiar with SharePoint and K2 for SharePoint.

Runtime Example

Scenario

You want to use a list of customers in a workflow to send a notification email of available specials.

This scenario uses a SharePoint list called Contact Details. The list stores a list of names and email addresses. You use the SharePoint method called Get List Item By View to iterate through each customer's details to send an email. The list is integrated with K2 for SharePoint and the workflow is started manually. The workflow contains three steps. A Create Reference step (creates references for each item in the list), a Loop step (that enables the workflow to loop through the referenced items), and a Send Email step that sends a customized email to a recipient.

The Loop step loops through all customers in the list and then follows the complete path to notify you when the campaign is completed.

You use the Loop Index reference as the identifier that calls each item in the list.

Steps