From a list of reference to string

Tristanct
Tera Expert

Hi,

I have in my form a list collector for the locations table. In my flow, I need to only get the name of each location and then join everything together in a string to pass it to a REST request.

Do you have any idea how to proceed?

Thank you,

1 ACCEPTED SOLUTION

The flow triggers on "Service Catalog". I am using the script on a "Set Flow Variables" step. I managed to do after searching for a long time. Here is my code:

var regionSysID = fd_data._1__get_catalog_variables.regions; // get the comma separated sys_ids
var list = regionSysID.split(","); //store it in an array
var regionArray = [];

for (var i=0; i < list.length; i++) {
    var loc = new GlideRecord('cmn_location');
    loc.get(list[i]);
    regionArray.push(loc.getDisplayValue());
}

return regionArray.toString();

View solution in original post

7 REPLIES 7

chrisperry
Giga Sage

Hi there,

It should be as easy as this one line of code (I'm not sure what the name of your Locations list field is, so update accordingly):

var locationNameList = current.getDisplayValue('u_locations');

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

Hi,

Thank you for your help, but it's not working. I get "Cannot convert null to an object" when I test my flow. The variable name in my form is called "regions" and as I said it's a list with references to the cmn_location table.

I tried:

var regionList = current.getDisplayValue("regions");

I also tried to iterate though the list, but that also did not work.

Ankur Bawiskar
Tera Patron
Tera Patron

@Tristanct 

Can you share the flow step where you are using this script?

Flow triggers on?

Regards
Ankur

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

The flow triggers on "Service Catalog". I am using the script on a "Set Flow Variables" step. I managed to do after searching for a long time. Here is my code:

var regionSysID = fd_data._1__get_catalog_variables.regions; // get the comma separated sys_ids
var list = regionSysID.split(","); //store it in an array
var regionArray = [];

for (var i=0; i < list.length; i++) {
    var loc = new GlideRecord('cmn_location');
    loc.get(list[i]);
    regionArray.push(loc.getDisplayValue());
}

return regionArray.toString();