Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Writing list collector display values to text fields with flow designer

dondandrea
Tera Contributor

I need to write the display values from a list collector to a text field. The ultimate use case is to use the values through an integration using integration hub. I can get that to work once I'm able to write the data to a text field.

I'm trying to avoid the creation of a new action if at all possible. I'm hoping ServiceNow has a way of doing this that is simple that I am simply unaware of. 

My first attempt was just dropping the pill in the filed and that returned a comma separated list of sys_id
 
My second attempt used the following block of code and achieved the same results.
 
var sillyName = fd_data._1__get_catalog_variables.variable_name;
return sillyName;
 
My third attempt was the following block of code that doesn't populate anything.
 
var sillyName = fd_data._1__get_catalog_variables.variable_name.getDisplayValue();
return sillyName;
 
Thanks in advance
8 REPLIES 8

Just posted a reply with what worked for me. Hopefully it can help you too...

Danny Rhoades
Kilo Guru

Here's what worked for me when using the Location [cmn_location] table and wanting to append the name value to the short description. If this was purely a data set contained within a variable table I think you'd need to use the Choice [sys_choice] or Question [question] table depending on the circumstance. 

Note: I built mine in a Subflow, but the same steps apply as a Flow.

 

Flow Designer Step-by-Step

Step 1.  Action > Look Up Records

Choose corresponding table

Conditions should be Sys ID > is one of > variable pill 

find_real_file.png

 

Step 2. Flow Logic > For Each

Drop newly available pill created from previous step

find_real_file.png

 

Step 3A. Action > Update Record

Use the trigger record pill in the Record spot - this will automatically update the table

Add the desired field to write the list collector results to

find_real_file.png

 

Step 3B. Click the f(x) button on the field you plan to update

Because I happened to want to update the short description, I used the suggested variable name and code below:

find_real_file.png

Subflow code:

var shortDesc = fd_data.subflow_inputs.requested_item.short_description; //declaring the variable

shortDesc += '; ' + fd_data._4__for_each.item.name; //appending to short description

return shortDesc; //returning a value
 
Note: If in a Flow, the first line would be:
var shortDesc = fd_data.trigger.requested_item.short_description;
 
 
The key parts are Look Up Records, For Each Logic, and then the script piece fd_data._[previous step number]__for_each.item.name - notice that the #4 in my example code above is related to the previous flow step and will differ based on your specific flow. 
 
The "item.name" part is what finally gave me the string value I was looking for. 
 
All of this results in the the short description being appended with each value listed in the list collector and separated by a semicolon. Hope this helps someone!

Great wokraround! But I'm concerned on the hardcoded .name value. Would it be better if we just use .getDisplayValue() or something similar?

I supposed that might work, try it and let us know what happens! 

The example method works by essentially dot-walking to whichever data point you'd like to use, which may not be the display value in every case.