We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to evaluate List Collector values in Flow Designer and trigger approval based on keyword

prudhvi67
Tera Contributor

Hi Team,
I have a requirement in ServiceNow Catalog + Flow Designer and need some guidance.

Scenario:
I have two List Collector variables in a catalog item:

Variable A (List Collector)
Variable B (List Collector)

Both variables reference the same table and store multiple selected values (sys_ids).

Requirement:
When a user submits the request:


If any selected value (from either List Collector) contains a specific keyword (e.g., "Network")
- > trigger an approval step


If no such values are selected
- > skip the approval

What I implemented:

Created a Flow Variable (String)
Used Set Flow Variables  - > Scripted mode
Wrote a script to:

Loop through List Collector values
Retrieve display values using GlideRecord
Store matching values in an array
Return the final values as a comma-separated string

Script Used:

var values = [];

var appPerm = fd_data.trigger.request_item.variables. my_variable_a + '';
var delPerm = fd_data.trigger.request_item.variables.my_variable_b + '';

var gr = new GlideRecord('my_table_name');
var FIELD = 'data_stored_field_name';
if (appPerm) {
var arr1 = appPerm.split(',');
for (var i = 0; i < arr1.length; i++) {
if (gr.get(arr1[i])) {
var val = gr.getDisplayValue(FIELD) || '';
if (val.toLowerCase().indexOf('network') > -1) {
values.push(val);
}
}
}
}
if (delPerm) {
var arr2 = delPerm.split(',');
for (var j = 0; j < arr2.length; j++) {
if (gr.get(arr2[j])) {
var val2 = gr.getDisplayValue(FIELD) || '';
if (val2.toLowerCase().indexOf('network') > -1) {
values.push(val2);
}
}
}
}values.join(',');

Flow Variable - > contains "network"


Expected Behavior:

Approval should trigger only when values containing "Network" are selected
Should not trigger for other values

1 REPLY 1

Laveena-Agarwal
Mega Sage

Hi @prudhvi67 

Please add some screenshots of your flow so that all the components, logic, and actions are clearly visible.