Understanding the Loop Step in a Workflow

  • 16 February 2021
  • 0 replies
  • 643 views

Userlevel 5
Badge +20
 

Using the Loop Step in a Workflow to Iterate through a Reference

KB002121

PRODUCT
K2 Cloud Update 8
K2 Five 5.0 to 5.3
SEE ALSO
 

Create Reference

Loop Step

 

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. 

Image

 

 

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:
 

  1. Create an input property by adding a new property to the method.
    Image
  2. 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.
    Image

    Image

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:

  1. Open K2 Designer.
  2. Browser to the category containing the SmartObject or service object method.
  3. Select Advanced SmartObject as the type on the General tab. This allows you to see the methods, otherwise you’ll only see the properties.
  4. Click the Properties and Methods tab.
  5. Select the Methods tab.
  6. Click on the List method and select Edit.
  7. Click NEXT on the Edit Method page.
  8. Select the Service Object method and click Edit.
  9. 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.

Image

How to Configure your Workflow

The following How to topics guide you through configuring a workflow with a Loop step:

  1. Standard workflow with a SmartBox Get List method that has an input property – How To: Create a Loop Through a List of Items
  2. 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 specific example is no longer applicable from K2 Five 5.3 and K2 Cloud Update 8 onward. There was an issue with the way that workflow references were able to filter when a SmartObject Method does not have the unique property as an input property. This issue was fixed in K2 Cloud Update 8 / K2 Five 5.3. You can use this how-to example in pre-K2 Five 5.3 environments where the issue still exists. Note that the issue also affected other service types, not just SharePoint SmartObjects. 

  3. 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

 


0 replies

Be the first to reply!

Reply