Ankur Bawiskar
Tera Patron
Tera Patron

Many a times there is a need to use list collector variable in the Flow Designer for multiple purposes such as creating 'n' number of catalog tasks or approval records based on list collector variable value count.

So we will have to use 'For Each' Action in Flow designer.

I have seen numerous questions around this so thought of creating a blog with the steps so that it helps community members.

Limitations: There is a known issue that it cannot be done directly KB0793340

Reason -> The Get Catalog Variables action returns a list collector as a comma separated string rather than an array. So we cannot use the 'For Each' action directly in your flow.

Resolution: So here is a workaround

  1. Create a custom flow action that takes list collector value string as the input
  2. Parse the string into an array
  3. Then output the array to be used in the For Each Loop.
  4. Then call this custom action in your flow and then use the output as per your needs

Steps:

1) Create custom flow action

a) Name - List Collector Convert to Array

2) Define the input variable as String

find_real_file.png

3) Create Script step

a) Map the input variable to the variable being used in script step -> by selecting the data pills -> inputs variable

b) Create output variable of type -> Array.String

Edit: As per few members update this is not working post upgrade from Orlando to new instance

So please change the Output type as Array.Object instead of Array.String

c) Use this script: To convert String to Array of Object (Edited)

(function execute(inputs, outputs) {
// ... code ...
  
  outputs.variable = inputs.variable.toString().split(',');
  
})(inputs, outputs);

find_real_file.png

find_real_file.png

4) Define the Output

find_real_file.png

5) Publish the Action

find_real_file.png

Usecase:

  1. Consider you have 1 list collector variable on your catalog item referring to Users table (sys_user)
  2. You want to set approvers based on how many users are present in list collector. If 3 users are selected then 3 approvers or 3 catalog tasks are to be created

Steps to implement with example: Trigger - Service Catalog

I assume you must have attached the flow to your catalog item.

  1. Use the "Get Catalog Variables" Action
  2. Call the custom Action "List Collector Convert to Array" and pass the list collector values as input
  3. Do a For-Each on the result from the custom action (array of sys_ids)
    3.1 Do a GlideRecord Lookup for the User based on the for-each value (sys_id)
    3.2 Use the "Ask For Approval" Action as you want and set the User as Output from 3.1 step

Screenshots:

find_real_file.png

find_real_file.png

find_real_file.png

 

 

find_real_file.png

find_real_file.png

 

Thanks for reading the blog and do provide your inputs/suggestions if any.

Hope you find this article helpful. Don’t forget to Mark it Helpful & also Bookmark.
Thanks,
Ankur Bawiskar

ServiceNow MVP 2020,2019,2018

My Articles & Blogs

99 Comments
samruddhi30
Tera Contributor

@nikhitha24 : For look up user record use for each loop and in that loop create task. It will create 3 task if your look up contains 3 matching records.

Edgar10
Tera Guru

Hi Ankur ,

 

The custom actions returns an object instead of an array and when using the output in the Foreach i can  access it properly.This is very helpful.

Edgar10_0-1708668306556.png

 

Regards,

Edgar

 

Kerry Hormann
Tera Contributor

Why is this STILL a problem?  The issue was found in 2020, identified and documented as a known issue in the New York release.

 

The functionality is broken.  It does not work at all, not as expected, not in an odd manner, not even with a trivial but non-ideal workaround.  This is the definition of a broken feature.

 

So the only solution is to hope that developers stumble upon this community article and struggle through implementing a custom action, something that has proven (from the comments in this thread) to be tricky to do correctly?

 

ABSOLUTELY UNACCEPTABLE.

 

Do better, ServiceNow.  Maybe you could use about 0.00001% of that $7 Billion in profit you took in 2023 and find time to actually SOLVE some real problems.  AI can wait another day, this is an easy one.

 

Kerry Hormann
Tera Contributor

@Edgar10it looks like your custom action needs to return the "variable" attribute of the JSON object created by the script.  You're just one step away - either modify the output of the script step or change the output of the action.

Josh Pirozzi
Kilo Sage

Hi everyone,

Has there been findings/configuration updates for the Action in Vancouver? I've tried building it with the update to the Output as an 'Array.Object', but cannot get the broken out/listed results. 

 

For background, we're trying to provide a List Collector on a Catalog Item where the customer can select multiple Business Applications and, based on the selection, the Flow Action recognizes each selected CI and triggers appropriate SubFlows.

 

Thanks!

Barath P
Tera Guru

Hi Team,

even i am also having same issue. i want to create catalog task and ask for approval on below for each logic. i have created custom action string convey to array. it is working but using look up records i can not able to select my table fields and approvers on below look up records. anyone have some idea to achieve my flow. please give reply if you have some idea.
Thanks and regards
Barath.P

tanwirsingh
Tera Contributor

@Barath P You need to use for each

Josh Pirozzi
Kilo Sage

After several iterations, and A LOT of trial and error, I've found a way to capture data from a List Collector and parse/trigger Tasks. For some reason, the Action route isn't working in Vancouver for our purposes. 

 

Background:

  • As of this comment, my org is on Vancouver Patch 4 HotFix 1b
  • Our purpose of developing the flow is to:
    • Provide a List Collector on a Catalog Item that is referencing our Business Applications (cmdb_ci_business_app) Table
    • Once submitted, the Flow recognizes the selected Business Application CI's and, based on various conditions, trigger Approval(s) and Catalog Tasks. 

Actions:

  1. Get Catalog Variables from the Catalog Item
    1. This is where the List Collector along with the selected Record(s) will come through to the Flow
  2. Look Up Records
    1. Table = Table Referenced on the List Collector Variable
    2. Conditions = SysID / IS ONE OF / Dot Walk to Step 1 List Collector > SysID
  3. For Each 
    1. Step 2 List Collector > Business Application
    2. Add a Function (fx button that becomes visible when you hover over the right of the 'Items' dot)
      1. Select 'Split' and add a comma followed by a Space

From here, you should be able to add IF Statements where the Condition references the For Each. In our case, I Dot Walked to the SysID of the Business Application and said IF the SysID Matched, then perform an action. 

 

Hope this can help those along with their Flows!

-Josh Pirozzi

svani
Tera Contributor

Hi @Ankur Bawiskar ,

This is exactly what i wanted this is sending approval request for groups also at once, but how can i check like atleast one member in group should approve it, now if any of the member of any group in the list approves others showing as no longer required , but atleast one member in each group should approve it.

Thanks in adavance

Siddharth4
Tera Contributor

Hi @Ankur Bawiskar

 

I'm working on an issue in which I have a requirement to create a list of record for which the associated records are not found. I try to apply your solution by creating the action but not able to apply that action in my flow.

 

@Ankur Bawiskar Kindly help me by answering in my post - Want to send a notification with the list of records for which the child record is not found in flow

 

Also please let me know in which step I need to apply this action to achieve the required functionality.

Thanks