Stored Procedure SmartObjects do not work with For Each loop

  • 16 February 2021
  • 0 replies
  • 119 views

Badge +4
  • Nintex Employee
  • 6 replies
 

For Each loop is returning a string of concatenated values instead of single item

kbt138442

PRODUCT
K2 Five
SEE ALSO
 
TAGS
How to Document
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.
LEGACY/ARCHIVED CONTENT
This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.

Issue

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.

Image

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.

Symptoms

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.

Resolution

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.

Image

 

Steps:

1.  Create a Data Field to store a semi-colon delimited list:

Image

 

2.  Use a Set Data Field event with the Inline Functions > Text > Join to build out this delimited list.  I.e.

a.  1;2;4

Or

b.  UniqueString1;UniqueString2;UniqueString4

* Be sure to 'Return all items that match filter' (4.7 and previous version) or 'All Items as a collection' (K2 Five).

Image

 

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.

Image

 

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

1,2,4

Or

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.

Image


0 replies

Be the first to reply!

Reply