- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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:
(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"):
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:
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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:
I then ran a very simple test, and it seemed to work:
However, when I run it in my actual flow, it does not work as expected:
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader