vermaamit16
Kilo Patron

Whenever we are working with a List Collector variable inside the flow designer, we usually encounter an error similar to the error below:

Unable to create serializable iterator for items:a8f98bb0eb32010045e1a5115206fe3a,0a826bf03710200044e0bfc8bcbe5d7a of class: class java.lang.String

 

We get this error because list collector variable is a comma separated string rather than an array, so the 'For Each' action is not able to iterate through that. To remediate this issue, we can follow the approach below:

 

1. Get the List Collector Variable Value from the Catalog Item using Get Catalog Variable Action. Let's assume that we have a list collector variable approvers, and we want to get the list of approvers within our flow to perform some task.

AmitVerma_0-1738662465967.png

2. Convert the List Collector String Variable to an array by using the Split Transformation Function. As the List Collector variable values are separated by Comma, we can split into Comma and convert it to an array. In this case, as the list collector variable references to sys_user table, we will get the sys_id of the users selected in the catalog item.

AmitVerma_1-1738662643054.png

3. Inside the ForEach flow logic, we can now make use of Lookup Record or any other flow action to fulfill the desired action. In this case, we will do a Lookup Record to get the User Record with the help of sys_id and thus use it further as required.

AmitVerma_2-1738662850981.png

 

When we execute this flow, we will get the particular user from the Lookup Record.

 

AmitVerma_3-1738663017302.png

 

Thank you for reading this blog. Please provide your inputs/suggestions if any. Hope you find this article helpful. Don’t forget to Mark it Helpful if it is able to assist you.


Thanks and Regards
Amit Verma

24 Comments
2mustang
Tera Contributor

How do you get the list collector's data pill to be accepted in a for each logic step? This appears to be blocked in my instances and PDI

Daniel_san
Kilo Sage

I’m experiencing the same issue as @2mustang

In the Zurich version, the List-type variable/pill is not accepted by the "For Each item in" step, so I’m unable to convert the sys_ids of the list into an array using the split function.

msedge_KHnsKA63bx.png

 

@vermaamit16: (or anybody who could help)
Do you know if we are doing something wrong... or maybe has this functionality been removed in the latest versions?

 

Thanks in advance for any help/tip

vermaamit16
Kilo Patron

Hi @2mustang @Daniel_san 

 

I tried reproducing the issue on my PDI. It looks like strict data pill type validations has been enforced by ServiceNow. However, I found a workaround to make it work.

 

Step 1 : Create a flow variable with type as Array.Object and map it's data pill to the for-each loop. Ensure that you apply split transformation function as well.

image.png

image.png

 

Step 2 : Change the Flow Variable type to String again. Notice that the Flow Variable Mapping in the for-each loop remains as it is.

image.png

image.png

 

Step 3. Next, make use of Set Flow variable action to set the flow of the flow variable created with the List Collector variable from your catalog item.

 

image.png

 

Step 4 : Finally, make use of Lookup Record action as mentioned in the blog above to get the relevant record.

image.png

 

Output -

image.png

Thanks and Regards

Amit Verma

Daniel_san
Kilo Sage

Thanks a lot @vermaamit16 for your reply and the workaround... you’re the best!! 

PS: Just a few minutes ago I managed to achieve the same result, but in a much more complicated way after a lot of trial and error, by creating a custom action (my first one 🙂) using a script to convert the variable’s list into an array.object to be used in the "for each".  Your approach is much more straightforward.