This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice This article is not considered official documentation for K2 software and is provided “as is” with no warranties.
When looping through a SmartObject, the count of time the loop should run is correct. However, the single item reference is returning all of the items in the collection as a single concatenated string instead of just the single item.
So if the SmartObject contains three rows, it will send three emails. However, instead of just a single item in each email it returns all items of the collection concatenated for all three emails/iterations. This behavior is not expected.
The workaround in (http://help.k2.com/kb002121) will only work if:
1. The referenced record ID must begin with 1.
2. The referenced record ID must be in running sequence number (1, 2, 3). Having only rows with ID (1, 3) will not work.
Another workaround exists, but will also have the requirements below:
1. There must be a unique field to identify the item within a delimited list, this can be an ID field or another unique field.
2. If using a unique string/text field instead, this must not contain the semicolon (;) character; as the semi-colon is used to split each item.
3. The SmartObject will need an input property/filter that will successfully retrieve a single item base on the unique field identified in requirement 1 above.
Overview of workaround:
We will store the unique IDs/unique field as a semi-colon-delimited list within a process data field. Use the For Each loop to iterate through this data field as it can handle a semi-colon delimited text and use corresponding SmartObject Load/List method or another Create Reference event to interact with each item within the loop.
1. Create a Data Field to store a semi-colon delimited list:
2. Use a Set Data Field event with the Inline Functions > Text > Join to build out this delimited list. I.e.
* Be sure to 'Return all items that match filter' (4.7 and previous version) or 'All Items as a collection' (K2 Five).
3. Use the For Each loop to target the semi-colon-delimited list data field and create the Single Item reference to be used in the loop.
4. Within the loop, this Single Item Reference field will return a single item of the delimited list (NOT all properties of the SmartObject). I.e.:
UniqueString1, UniqueString2, UniqueString4.
5. Within this loop, you can call the Load OR Get List method of the SmartObject in question to get and use the data as needed or use another Create Reference event within the loop if you want to access that row as an item reference instead.