I need to populate List Collector values into SC task description using flow designer

SatheeshBangaru
Tera Contributor

I have a List Collector type variable called 'server_name' that uses the cmdb_ci_server table. Using Flow Designer, I need to populate the multiple server names in the sc_task description, but when I try, the sys_ids are getting populated instead. could any one of them help me with this?

2 REPLIES 2

Craig Evans
Tera Contributor

List Collector fields use sys_ids similar to reference fields which is why these are getting returned. The main difference being the list does not create a 1:1 relationship. 

I assume you are using data pills in order to populate the description field. You may need to script this by returning the values display values. It would look similar to below.

 

var list = fd_data.<DATA PILL NUMBER>.server_name.split(',') //This will collect the list fields data and split based off each sys_id;

 

var result = ''; //String to restore the result of names;

 

var rec = new GlideRecord('cmdb_ci_server'); //Look up the CI Record

for (var i = 0; i < list.length; i++) {

rec.get(list[i]);

result += rec.name + '\n'; //Pushes the CI name into the string and performs a line break between each.

}

 

return result; //Returns the multi-line string of CI names.

 

 

I hope this helps.

Runjay Patel
Giga Sage

Hi @SatheeshBangaru ,

 

You can write script to set the comma separated value in description like below.

First get the value using get variable and then create catalog task. Use script to set the display value.

 

RunjayPatel_0-1732527371753.png

 

Script:

var asset = fd_data._1__get_catalog_variables.server_name; 
var arr = asset.split(',');
var serverName =[];
var gr = new GlideRecord('cmdb_ci_server');

arr.forEach(function(currentValue, arr) {
   
    gr.get(currentValue);
    gr.query();
    if (gr.next()) {
		serverName.push(gr.display_name); // replace with actual name
        
    }
});


return serverName.toString();

 

I have tested it and working fine.

RunjayPatel_1-1732527647202.png

 

 

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------