How to retrieve string name of selected list items in flow designer

Brian Hofmeiste
Kilo Guru

Hello!  

 

My form has a list of departments and users are able to select multiples.  In flow designer I want to grab the names of all departments they selected.  Is this possible with just flow designer or do i need a script?  If a script, can you suggest something?  thanks so much.

 

Brian

1 ACCEPTED SOLUTION

Brian Hofmeiste
Kilo Guru

Thanks to everyone who provided feedback on this.  Each of your answers helped me determine my best approach.  I ended up doing the following:

 

1. Retrieve the list of departments they selected on form.  This comes in the form of a comma separated string.

2. I created a custom action to turn that comma separated string in to an array.

3. I used a FOR EACH loop in the flow designer to cycle through the array.  I wrote each department name in to a string called departments.

4. i added that departments string to the story record where I wanted it to land.

View solution in original post

7 REPLIES 7

Voona Rohila
Mega Patron
Mega Patron

Hi @Brian Hofmeiste 

Can you explain in detail of your requirement? You want to access all the department names instead of sys_id's in flow designer?


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

On our request form we ask them to select departments like this:

 

BrianHofmeiste_0-1726176493375.png

 

Then we want to take the departments they selected and paste them into the description field of a new story we created.  Like this.

 

BrianHofmeiste_1-1726176615978.png

 

But this does not work - the "who is involved"  is a list object so the story description shows nothing when its created.  

 

BrianHofmeiste_2-1726178015174.png

 

 

How do I get the selected list items into the story description field? 

 

 

You need one more script action step or use flow variable step before this step ..sample code

var selDep = current.variables.departments.toString().split(','); // Adjust field name as needed

var departmentNames = [];
for (var i = 0; i < selDep.length; i++) {

var deptRecord = new GlideRecord('cmn_department'); // Adjust table name
if (deptRecord.get(selDep[i])) {
departmentNames.push(deptRecord.name); // Assuming 'name' is the field for department name
}
}gs.info('Selected Departments: ' + departmentNames.join(', '));

Brian Hofmeiste
Kilo Guru

This article seems relevant... looks like the list collector is providing a comma separated list to flow designer... bummer.  This means I have to parse out that string into an array so i can lookup each or the sysIDs.... unless you can think of a better way.

 

Unable to use a list collector variable in the Flow Designer 'For Loop' action - Support and Trouble...