When using references in a workflow, you may find that the entire list of items in the reference is returned instead of a single item. This can occur when the reference's list method does not have an input property (filter) to retrieve a single record, so it returns all items in the reference, concatenated together, which is typically not what you need.
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 article (and the links at the end) 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.
For information about using the Create Reference and Loop steps, see the following Help topics:
Example of Using a Reference with the Loop Step
In this example you are sending an email to all customers in a list. The workflow loops through the email step until all customers on the list have been emailed, after which the workflow continues. In the case where the reference's list method does not contain an input property to identify individual items within the reference, you can use the reference together with the Loop step in order to send a series of emails. This works for other scenarios where you must perform an action in the workflow per item in the reference.
Workaround and More Information
For a typical reference that has a unique identifier, the SmartObject list method has an input property to load a 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 references to retrieve 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.
SmartObject methods, such as the Get List Items by View method for SharePoint used here, 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. While SmartBox SmartObject list methods automatically include the input property for passing in the ID, but other SmartObject methods (such as SharePoint, SQL Stored Procedures, and Web Service methods) may not. To use these methods you can do one of the following to perform an action on each individual item within the reference:
- Create an input property by adding a new property to the method.
- Use the Loop index to create the identifier and then use the Loop Index to join the identifier with the data. To configure the Loop index see How To: Create a Loop through a List of Items using SharePoint.
How to check the SmartObject method for an input property
Check to see if your SmartObject or service object method that you want to use has an input property. You can do this by following these steps:
- Open K2 Designer.
- Browser to the category containing the SmartObject or service object method.
- Select Advanced SmartObject as the type on the General tab. This allows you to see the methods, otherwise you’ll only see the properties.
- Click the Properties and Methods tab.
- Select the Methods tab.
- Click on the List method and select Edit.
- Click NEXT on the Edit Method page.
- Select the Service Object method and click Edit.
- On the Edit Service Object method bindings page see the input properties and if they are mapped to a value. Below is an example of a SmartBox Get List method.
How to Configure your Workflow
The following How to topics guide you through configuring a workflow with a Loop step:
- Standard workflow with a SmartBox Get List method that has an input property – How To: Create a Loop Through a List of Items
- Configure a workflow that integrates with SharePoint and uses a SharePoint SmartObject method that does not have an input property, you will use the Loop Index to link the Identifier to the referenced item’s value. - How To: Create a Loop through a List of Items using SharePoint
This approach is no longer necessary on K2 Five 5.3 and K2 Cloud Update 8.
- Configure a workflow that integrates with SQL Store procedures and uses a SQL SmartObject method that does not have an input property. – How To: Loop through a list from a SQL stored procedure