Flow Designer Issue: IF Statements on List Collector Fields Using Choice List

jmiskey
Kilo Sage

We have a scoped app where a person fills out a Record Producer on the Service Portal, and it populates a record in a custom table.  That part works fine.  But we are creating a flow that does various things when the record is first added to the table, and are having issues creating an IF statement.  Basically, we have a List Collector field where the user can enter multiple values.  If a "certain" value is selected from that list, we would like the flow to update another field with some information it looks up. 

 

We have this working correctly on a few fields whose data source is another custom field.  However, we have a few instances in which the List Collector's data source is from the sys_choice table.  And we cannot get this one to work properly.  

 

First, here are what the key data elements in the sys_choice table look like:

jmiskey_0-1757355177162.png

(there are actually 17 in all, but these are just the first few)

 

And here is how the field in the Custom Table is set up (note the field type is "List"):

jmiskey_1-1757355401421.png

 

The field works properly - I am able to select multiple values to this field.

 

However, If I try to create an IF statement in a Flow based of this field, I do not get a "contains" option like I do for my List Collector fields which are pulling from custom tables.  This is what I see:

jmiskey_2-1757355572115.png

 

As you can see, there is no option for "contains".

 

I know I could probably create a custom table of all the options, and use that as the data source instead.  But there is already a lot of historical records out there, so to make those sort of changes would be problematic to the existing records.  So that is really not a good option in this case.

 

How can I get this to work, so my IF statement can look for one particular value among all the selected values for this field? 

 

Thanks

 

Thanks

 

 

 

 

 

1 ACCEPTED SOLUTION

OK, nothing was working, so I came at this in a different manner.  I had created another Custom Action a while back that converts List Collectors to Strings.  So I ran that against the table field.  Then when I tried to do an IF statement on that converted value, I had access to use CONTAINS, and accomplish what I need.

View solution in original post

12 REPLIES 12

M Iftikhar
Mega Sage

Hi jmiskey,

I see the issue. The problem is that Flow Designer's standard contains option isn't available for List Collector fields that use sys_choice as a data source. This happens because the field's value is stored as a comma-separated string, not as a list of references.

To handle this, the most reliable solution is to use a Script step in Flow Designer to check for the desired value.

 

Solution: Use a Script Step in Flow Designer

  1. Add a Script Action: Add a new Script action in your flow.

Write the Logic: Use the following example script to get the field value, split it into an array, and check if it contains your target choice.

// Get the comma-separated string value of the list collector field.
var selectedChoices = fd_data.trigger.current.[your_list_collector_field_name].toString();

// Convert the string into an array of values.
var choiceArray = selectedChoices.split(',');

// Check if the array of selected values includes your target value.
if (choiceArray.includes('your_choice_value')) {
    // If the value is found, perform your action
    // For example: fd_data.script.is_match = true;
}

This approach ensures your flow works correctly with sys_choice based List Collector fields, without needing to modify historical records.
Hope this helps!


Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks for the reply Muhammad!  I am away most of the next two days, but will definitely try to incorporate it when I get back to the office, and report back and let you know if I can get it to work.

Muhammad,

 

Having some issues.  It is not working as expected.  I decided to create a Custom Action, as I will need to use this in multiple places.  Here is how I designed my Custom Action:

jmiskey_0-1757591708688.png

jmiskey_1-1757591723218.pngjmiskey_2-1757591732664.pngjmiskey_3-1757591745714.pngjmiskey_4-1757591753688.pngjmiskey_5-1757591771519.png

 

I then ran a very simple test, and it seemed to work:

jmiskey_6-1757591793952.pngjmiskey_7-1757591806631.png

 

However, when I run it in my actual flow, it does not work as expected:

jmiskey_8-1757591839979.png

 

You can see the the value I am searching for does exist in my search string, yet it returns FALSE.

 

Note that my Custom Action appears in the Global Scope, and my Flow is in a Scoped App, but as you can see from my first screen print, I have this accessible from "All application scopes" (and we have does this successfully before with other Custom Actions).

 

Any ideas what I am doing wrong?

@jmiskey 

when flow calls your action did you add log and see what came in the output variable?

If you see your flow is passing 2 sysIds but not as string.

If they are string then they should be comma separated.

Something wrong in the way input is passed to the Action

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader