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

Comments
Tera Expert

Worked perfectly and right on time for my use-case.

Tera Contributor

It is returning only the first User in the List collector, not all the list of Users. Can you help on how to get the all the Users in the List Collector Variable

Kilo Patron
Kilo Patron

@Vasu2 

 

It is because of the fact that we are iterating the list of users in a for-each flow logic, thus you get only one user at a time. If you want to get all the users, you can make use of a Flow Variable and append the user found within the foreach flow logic. 

 

You can use this flow variable as and when required inside the flow. If you have any specific requirement, let me know so that I could be able to assist you better.

Tera Contributor

In my use case, we have a List Collector variable in the catalog form which is pointing out to User table, once the catalog item is submitted it goes for one Group Approval. once that group approves then the approval should goes to all the List collector users at the same time. Currently the Approval is going one after the other, which means if there are four users, the Approval first goes to first user in the List collector, if Approves then it is going to next user approval.

Please help me where and what to change to send Approvals for all the users at the same time.

Thanks in advance.

 

Kilo Patron
Kilo Patron

@Vasu2 

 

Refer below screenshots to get an idea on how you can achieve this -

 

AmitVerma_1-1741594143108.png

 

AmitVerma_2-1741594173398.png

 

AmitVerma_4-1741594402867.png

 

 

// Initialize the approver with the current approver value
var approver = fd_data._4__for_each.item;
// Append the approver to the approverUsers flow variable with a comma
var approverUsers = fd_data.flow_var.approverusers + approver + ','; 
// Return the updated approverUsers
return approverUsers;

AmitVerma_5-1741594439551.png

 

Output :

AmitVerma_6-1741594457155.png

 

 

Tera Contributor

Thanks for the response,

 

1) Somehave I can not able to select the ApproverUsers List in the Ask for Approver step

Vasu2_0-1741828416254.png

2) when I test with a RITM in flow designer, the output of the foreach loop (step before ask for approver) is showing as like below screenshot

Vasu2_1-1741828607796.png

 

Kilo Patron
Kilo Patron

@Vasu2 

 

Ensure that you set the flow variable as below and give it a retry:

AmitVerma_0-1741843839795.png

 

Tera Expert

@vermaamit16 , If I wanted the lookup script to assist me with getting the "name" of the user in the list collector vs the sys_id, what would that script look like? 

 

I have my For Each

kdelbridge_0-1741985762195.png

 

I then built my Lookup User Record 

kdelbridge_0-1741987670944.png

I them am attempting to update the short description using values from the Look Up User Record

 

kdelbridge_0-1741988375236.png

 

It is NOT bringing over the name that I pulled from Node 4 Look Up User Record.

 

kdelbridge_1-1741988575369.png

 

Any ideas? I am still learning, so please be gentle.

 

Tera Expert

@vermaamit16 , If I wanted the lookup script to assist me with getting the "name" of the user in the list collector vs the sys_id, what would that script look like? 

 

I have my For Each

kdelbridge_0-1741985762195.png

 

I then built my Lookup User Record 

kdelbridge_0-1741987670944.png

then attempted to update user record pulling from Node 4

 

kdelbridge_1-1741989877141.png

 

Unfortunately, the name did not pull over on short description as hoped.

 

kdelbridge_2-1741989942196.png

 

Any idea where I may have gone wrong here?

 

Thanks in advance.

 

Tera Contributor

Hi @vermaamit16, It is working now, thanks for the help. 

I am trying to achieve another scenario where in my catalog Item,  I have a List Collector field called 'role' and each role will have single or multiple owners. We can select multiple roles at a time in the List collector. when the catalog item is submitted, it should go to all the role owners approval at a time . If there is multiple Role owners for a role then anyone can Approve or Reject the role. If anyone approve/Reject then we no need another one Approve/Reject for that role. If all the Approvals (Approve/Reject) for the all the selected roles is completed then a task should be open and in that task description all the approved role names should appear. 

Can you help on this flow Logic, Thanks in Advance


Kilo Patron
Kilo Patron

@kdelbridge 

 

As per your screenshots, you are trying to make use of Update Record Action outside the For-Each loop. In your list collector variable, you will get series of user sysIDs thus either you need to move the Update RITM Record action inside the for-each loop or collect the user names in a Flow Variable and then pass the flow variable to your Update Record action.

Tera Contributor

Hello @vermaamit16 ,

I have followed all the steps mentioned in your article, but when I try to save my flow, I receive the following error:

"Index 1 out of bounds for length 1."

Could you please guide me on how to resolve this issue?

Thank you.

Kilo Patron
Kilo Patron

@ShashikantP7021 

 

Can you please share some screenshots of your flow configuration?

Tera Contributor

Hello @vermaamit16 

Please find below the flow screenshot and error screenshot for your reference.

I'm not sure why I am encountering this error, as I have followed all the mentioned steps.

Could you please guide me?

Thank you.

Error FlowError FlowStep 3 inline ScriptStep 3 inline ScriptStep 3 look up recordStep 3 look up recordStep 2 splitStep 2 splitstep 2 for each loopstep 2 for each loopStep 1 get catalog variablesStep 1 get catalog variables

Kilo Patron
Kilo Patron

@ShashikantP7021 

 

Could you please share a screenshot of the delimiter you have used in the split function? I suspect that you have either missed it or it is incorrect. It should be ,

Tera Guru
Tera Guru

Hello @vermaamit16 

I am unable to select the Flow Variable Type as record.user, as you mentioned in the screenshot. Could you please assist me with this?

Thank you,Flow Variables.png

 

Kilo Patron
Kilo Patron

Hi @Abhijeet_Pawar 

 

You are going in the right direction. Select Reference as variable type and click on the > icon to dot-walk to sys_user table as shown below:

 

AmitVerma_0-1742787079937.png

 

Tera Guru
Tera Guru

In my use case, we have a List Collector variable in the catalog form which is pointing out to User table, once the catalog item is submitted it goes for one Group Approval. once that group approves then the approval should goes to all the List collector users at the same time. Currently the Approval is going one after the other, which means if there are four users, the Approval first goes to first user in the List collector, if Approves then it is going to next user approval.

Hello @vermaamit16 ,

I reviewed your solution for the above post and implemented all the steps you mentioned. Everything is working fine, but the approvals are not proceeding one after another. When I approve the first request, the other approvals change to "No Longer Required."

Could you please guide me on how to resolve this?

Mega Sage

@vermaamit16 
In my case, I've a list collector type two variables which are groups and users on catalog item. 
When user is submitting the request by selecting multiple groups and users in the variables then after submition  I need to generate the approval on RITM for manager of each group selected in the groups variable.

My approval is not getting generated for each group manager.
Could you please help me out?

Kilo Patron
Kilo Patron

@Aishwaryaaa_ 

 

You need to first do a Lookup Record to Group table followed by setting the value of Group Manager to a flow variable. This flow variable can be used in the Ask for Approval action to trigger the approval to the respective Group Managers. Refer below screenshots:

AmitVerma_0-1751980073297.png

AmitVerma_1-1751980142065.png

AmitVerma_2-1751980183113.png

AmitVerma_3-1751980210464.png

 

Output:

AmitVerma_4-1751980255370.png

 

AmitVerma_5-1751980267295.png

 

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

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

Kilo Patron
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

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.